두 개의 버튼이있는 ListView 항목이 있습니다. 여러 개의 ListView 항목이 있으므로 많은 버튼이 있습니다. 각 버튼에 다른 값을 할당하려면 어떻게합니까? 내가 원하는 것은 모든 버튼이 같은 액티비티로 연결된다는 것입니다.하지만 새로운 액티비티로 이동하면 버튼이 할당 된 값을 보냅니다. 그런 다음 활동이 값을 처리 할 수 있습니다. 여기 내 baseAdapterlistView에서 버튼에 다른 값을 할당하는 방법 - Android
class CreateCommentLists extends BaseAdapter{
Context ctx_invitation;
String[] listComments;
String[] listNumbers;
String[] listUsernames;
public CreateCommentLists(String[] comments, String[] usernames, String[] numbers, DashboardActivity context)
{
super();
ctx_invitation = context;
listComments = comments;
listNumbers = usernames;
listUsernames = numbers;
}
@Override
public int getCount() {
if(null == listComments)
{
return 0;
}
// TODO Auto-generated method stub
return listComments.length;
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return listComments[position];
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View v = null;
try
{
String inflater = Context.LAYOUT_INFLATER_SERVICE;
LayoutInflater li = (LayoutInflater)ctx_invitation.getSystemService(inflater);
v = li.inflate(R.layout.list_item, null);
TextView commentView = (TextView)v.findViewById(R.id.listComment);
TextView NumbersView = (TextView)v.findViewById(R.id.listNumber);
TextView usernamesView = (TextView)v.findViewById(R.id.listPostedBy);
Button usernameButton = (Button)v.findViewById(R.id.listUsernameButton);
Button numberButton = (Button)v.findViewById(R.id.listNumberButton);
commentView.setText(listComments[position]);
NumbersView.setText(listNumbers[position]);
usernamesView.setText(listUsernames[position]);
usernameButton.setText("Go to " + listUsernames[position]);
numberButton.setText("Go to " + listNumbers[position]);
}
catch(Exception e)
{
e.printStackTrace();
}
return v;
}
}
그리고 당신의'Intent'는 텍스트로 설정 한 것과 동일하게 버튼에 할당 된 값을 원하는? 인 텐트에 추가 값을 입력하고 시작된 활동에서 값을 읽을 수 있습니다. – ozbek
하지만 어떻게해야합니까? –
귀하의 의도를 게시하십시오 :) – ozbek