我有一個複雜的listview,我已經在列表視圖項上設置onclick,但我想爲listview的每一行做它,它應該打開那裏各自的活動(不同的活動)。我該怎麼辦?我的代碼是在這裏..如何在列表視圖行上設置onclick?
public class Content extends Activity {
String [] content = {"Linked List", "Write your own function", "programs", "Trees", "Sorting Techniques", "C Pointer",
"C Functions", "C Statements", "C Arrays", "C Variables", "C Structures", "C Macros", "C Headers", "C File Operations",
"C Declarations and Definitions", "C Functions-built-in", "C Functions-The Main Function", "OS Concepts",
"General Concepts", "Compiling and Linking"};
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.content);
ListView list = (ListView)findViewById(R.id.content_listView);
ContentAdapter ca = new ContentAdapter();
list.setAdapter(ca);
list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
/*Here I want to do something that after
clicking on any listview row it should open there respective page
*/
}
});
}
class ContentAdapter extends BaseAdapter {
@Override
public int getCount() {
// TODO Auto-generated method stub
return content.length;
}
@Override
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int arg0) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(int index, View v, ViewGroup vg) {
// TODO Auto-generated method stub
v = getLayoutInflater().inflate(R.layout.custom_content, null);
TextView content_txt = (TextView)v.findViewById(R.id.custom_content_textView);
content_txt.setText(content[index]);
return v;
}
}
}
使用'content [arg2]'並使用intent和startActivity。 – Raghunandan