Answer the question
In order to leave comments, you need to log in
How to assign an id to list items?
I want to open a new activity when I click on a list item.
The list is formed like this:
for (int i = 0; i < name.length; i++) {
Log.d("myLogs", "i = " + i);
View item = ltInflater.inflate(R.layout.item, linLayout, false);
TextView tvName = (TextView) item.findViewById(R.id.tvName);
tvName.setText(name[i]);
TextView tvPosition = (TextView) item.findViewById(R.id.tvPosition);
tvPosition.setText("Должность: " + position[i]);
TextView tvSalary = (TextView) item.findViewById(R.id.tvSalary);
tvSalary.setText("Оклад: " + String.valueOf(salary[i]));
item.getLayoutParams().width = LayoutParams.MATCH_PARENT;
item.setId(i+1);
item.setOnClickListener(this);
item.setBackgroundColor(colors[i % 2]);
linLayout.addView(item);
}
public void onClick(View v) {
switch (v.getId()) {
case R.id.1:
Intent intent = new Intent(this, ActivityTwo.class);
startActivity(intent);
break;
default:
break;
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question