I have two java classes below that make a customListView. I got the code from somebody I'm working on an app with but I don't really understand her code. I want to add buttons that will bring you to an new activity when they are clicked, and change the text of "Description of "+itemname[positionof] to be different for each section(she has them all grouped so I can't change each individually).
I know that you can do something like
public void onLeaderboardClick(View view)
{
Intent intent = new Intent(MainActivity.this , Leaderboard.class);
startActivity(intent);
}
to start the new activites but as I've said above I'm just not sure how to split them up indivually so each can have a diffeernt onClickValue
public class ListMainActivity extends Activity {
ListView list;
String[] itemname ={
"Capture The Flag",
"Leaderboard",
"Log out"};
Integer[] imgId={
R.drawable.capturetheflag,
R.drawable.leaderboard,
R.drawable.logout,
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list_main);
CustomListAdapter adapter=new CustomListAdapter(this, itemname, imgId);
list=(ListView)findViewById(R.id.list);
list.setAdapter(adapter);
list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// TODO Auto-generated method stub
String Selecteditem= itemname[+position];
Toast.makeText(getApplicationContext(), Selecteditem, Toast.LENGTH_SHORT).show();
}
});
}
}
and
public class CustomListAdapter extends ArrayAdapter<String>{
private final Activity context;
private final String[] itemname;
private final Integer[] imgid;
public CustomListAdapter(Activity context, String[] itemname, Integer[] imgid) {
super(context, R.layout.mylist, itemname);
this.context=context;
this.itemname=itemname;
this.imgid=imgid;
}
public View getView(int position,View view,ViewGroup parent) {
LayoutInflater inflater=context.getLayoutInflater();
View rowView=inflater.inflate(R.layout.mylist, null,true);
TextView txtTitle = (TextView) rowView.findViewById(R.id.item);
ImageView imageView = (ImageView) rowView.findViewById(R.id.icon);
TextView extratxt = (TextView) rowView.findViewById(R.id.textView1);
txtTitle.setText(itemname[position]);
imageView.setImageResource(imgid[position]);
extratxt.setText("Description of "+itemname[position]);
return rowView;
};
}