2013-04-08 18 views

回答

0

您可以通过扩展listactivity类做到这一点...

只是扩展该类并覆盖listitemclick()函数...

,并在...

开始新活动... Intent i = new Intent(this,yourclass.class); startActivity(i);

1

那么,你会首先,为您的列表视图中创建一个项目布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" > 

     <Button 
      android:id="@+id/button1" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="Show link1" 
      /> 
</LinearLayout> 

这是你布局的ListView控件:

<ListView 
    android:id="@+id/ListView1" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" > 
    </ListView> 

在活动文件

myAdapter adapter = new myAdapter(
      context, R.layout.your_list_item, buttonStrings); 
ListView listView = (ListView) findViewById(R.id.ListView1); 
    listView.setAdapter(adapter); 
    listView.setOnItemClickListener(new OnItemClickListener() { 

     @Override 
     public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 
      // do your logic here with position or id 
      Intent myIntent = new Intent(currentActivity.this, nextActivity.class); 
      startActivity(myIntent); 
     } 
    }); 

MyAdapter,你可以用你的列表项播放(在你的情况下提供一个名称的按钮)

相关问题