【问题标题】:start new ListActivity from ListActivity within tabview在 tabview 中从 ListActivity 开始新的 ListActivity
【发布时间】:2012-09-06 16:43:41
【问题描述】:

我有 4 个标签的 tabview,我正在使用 TabHost 来显示我的应用程序的标签。 每个选项卡都由另一个从 ListActivity 扩展的类填充,这是代码

public class TabbedActivity extends TabActivity {

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.tab_layout);

    TabHost tabHost = getTabHost();

    // Tab for Catalog
    TabSpec catalogspec = tabHost.newTabSpec("Catalog");
    catalogspec.setIndicator("Complete Catalog Fall 2012", getResources().getDrawable(R.drawable.ic_catalog));
    Intent catalogIntent = new Intent(this, Category.class);
    catalogspec.setContent(catalogIntent);
// Adding all TabSpec to TabHost
    tabHost.addTab(catalogspec); // Adding catalog tab
}

这是另一个意图的代码

public class Category extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {       
    super.onCreate(savedInstanceState);
    setContentView(R.layout.list_of_data);
 Categories = new ArrayList<String>();
    fillListCategories();

    myListItems = new ArrayList<String>();
    adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, Categories);
        this.setListAdapter(adapter);
}}

在Listview有项目列表,我的观点是如何设置Onclick在同一个Tab中打开另一个“ListActivity”?!!

【问题讨论】:

  • 您是否尝试过在 onClick 上放大视图?
  • 不,实际上我在 android 中很新鲜,只有 3 周,,你能改进我的细节吗?,,我想让标签保持可见

标签: android android-intent listactivity tabview


【解决方案1】:

在您的 Category 类中,像这样添加一个 onClickListener:

public class Category extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {       
super.onCreate(savedInstanceState);
setContentView(R.layout.list_of_data);
Categories = new ArrayList<String>();
fillListCategories();

myListItems = new ArrayList<String>();
adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,   Categories);
    this.setListAdapter(adapter);
    this.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  @Override
  public void onItemClick( AdapterView<?> parent, View item, 
                           int position, long id) {
    mSelectedCategory = (String)parent.getItemAtPosition(position);

    Intent intent = new Intent(getBaseContext(), ScreenTwo.class); 
            intent.putExtra("name", mSelectedCategory.(WHATEVER INFO YOU NEED ABOUT THE CATEGORY);
            startActivity(intent);  
  }
});
}}

ScreenTwo.java 看起来像具有 ListAdapter 的类别类,但具有通过意图传递的信息:

public class ScreenTwo extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {       
super.onCreate(savedInstanceState);
setContentView(R.layout.list_of_data);
Bundle b = getIntent().getExtras(); 
    String Name = b.getString("name");
Categories = new ArrayList<String>();
fillListCategories();

myListItems = new ArrayList<String>();
adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,    Categories);
    this.setListAdapter(adapter);
}}

【讨论】:

  • 我现在正在尝试,但我还有另一个问题,如何通过 Object 在列表视图中设置原始值有 5 个值,我已经在使用适配器,并且当我使用该类时从活动扩展它工作正常,但是当我使用扩展列表活动时,它没有显示任何东西??
  • 对不起,我不太明白你的问题
  • 类别应该重定向到的第二个意图是列表视图,但列表项不是字符串,它是项目的对象,这个项目有 5 个值,我使用一个类获取并设置它们的值我现在使用适配器填充数据,如何用这个适配器数据填充列表视图行??!!
  • 是的,膨胀视图是当前屏幕顶部的视图,所以它会这样做:(
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-01-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多