OnItemClickListener itemClickListener = new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View container, int position, long id) {
// Getting the Container Layout of the ListView
LinearLayout linearLayoutParent = (LinearLayout) container;
// Getting the inner Linear Layout
LinearLayout linearLayoutChild = (LinearLayout) linearLayoutParent.getChildAt(1);
// Getting the Country TextView
TextView tvCountry = (TextView) linearLayoutChild.getChildAt(0);
//here insted on toast i want to start different activity for different items
Toast.makeText(getBaseContext(), tvCountry.getText().toString(), Toast.LENGTH_SHORT).show();
}
};
// Setting the item click listener for the listview
listView.setOnItemClickListener(itemClickListener);
}
ответ
Какую деятельность вы хотите начать? Нормальный метод:
Цель намерения = новое намерение(); StartActivity (намерение);
Добавить tvCOuntry в "EXTRAS" и получить это в следующем действии, которое одинаково для каждого списка и выполнить соответствующее действие. Используйте следующий код, чтобы начать новую деятельность
listview.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position,long id) {
LinearLayout linearLayoutParent = (LinearLayout) container;
// Getting the inner Linear Layout
LinearLayout linearLayoutChild = (LinearLayout) linearLayoutParent.getChildAt(1);
// Getting the Country TextView
TextView tvCountry = (TextView) linearLayoutChild.getChildAt(0);
Intent intent=new Intent(THIS_ACTIVITY.this,ACTIVITY_TO_START.class);
intent.putExtra("Country",tvCountry.getText().toString());
startActivity(intent);
}
});
После этого используем следующий код в «OnCreate» в следующей деятельности
String passedArg = getIntent().getExtras().getString("country");
в следующей деятельности и выполнять действия в соответствии с «passedArg» строка
может я отправить мой код и и может сделать некоторые изменения для меня –
Конечно, пожалуйста, укажите ваш почтовый идентификатор – Kunal
[email protected] и может у также предоставить ур почтовый идентификатор –
Что вы думаете об этом? –
@RandykaYudhistira, когда я нажимаю какой-либо элемент в виде списка, затем перебираю меня на другую активность для указанного элемента. –