我正在尝试获取列表项的索引,通过它我可以为另一个活动中的不同项目设置不同的视图。这是我的代码..
String description[] = {"inspiron","pavilion","macbook"}; /* i want this list on another activity after clicking listitem of first activity.*/
ArrayList<String> listDesc = new ArrayList<String>();
String ArrayDesc[] = null;
ListView listViewDesc;
ArrayAdapter<String> listAdapterDesc;
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.category);
for(int i = 0;i<description.length;i++)
{
listDesc.add(description[i]);
}
ArrayDesc = (String[]) listDesc.toArray();
listAdapterDesc=newrrayAdapter<String>this,android.R.layout.simple_spinner_item,ArrayDesc);
listViewDesc.setAdapter(listAdapterDesc);
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3)
{
lstView.setOnItemClickListener(new OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> a,View v, int i, long l)
{
/*here i want some code to extract list item index from list to set
different lists according to the item click on another view.*/
Intent intent = new Intent(getApplicationContext(), categorySelected.class);
startActivity(intent);
}
});