I'm rather new to programming, but I've got a listview which displays the contents of a database. It also has a button which can be pressed. the code im having trouble with is in my adapter class for the listview. Ideally I would like to pass information about the row in which the button has been pressed into the new activity. so far if I take out the startActivity I can change the text of the button so I know the button works, but as soon as I try to add a startActivity it will just crash. the activity that I'm trying to open is just so I know that I can get the button to work (hence ive called it success) so I can then implement this into another app. can someone help me as to why the new activity doesn't open and how to correct it, thanks in advance.
@Override
public View getView(int position,View convertView,ViewGroup parent)
{
View row = convertView;
final LayoutHandler layoutHandler;
if(row == null)
{
LayoutInflater layoutInflater = (LayoutInflater)this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = layoutInflater.inflate(R.layout.row_layout,parent,false);
layoutHandler = new LayoutHandler();
layoutHandler.NAME = (TextView)row.findViewById(R.id.tvViewRow);
layoutHandler.BtntoClick = (Button)row.findViewById(R.id.BtnToClick);
row.setTag(layoutHandler);
}
else
{
layoutHandler = (LayoutHandler) row.getTag();
}
DataProvider dataProvider = (DataProvider)this.getItem(position);
layoutHandler.NAME.setText(dataProvider.getName());
// this is the method once the button has been clicked final Button btn = layoutHandler.BtntoClick;
btn.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view) {
btn.setText("clicked");
Log.e("intent builder", "onClick method started");
Intent intent = new Intent(ListDataAdapter.this, Success.class);
startActivity(intent);
}
private void startActivity(Intent intent) {
}
});
return row;
}