-1

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;


}
krisC
  • 1
  • 1

1 Answers1

0

The problem maybe in your intent but i am not entirely sure without knowing the name of your activities

Intent intent = new Intent(ListDataAdapter.this, Success.class);

If ListDataAdapter is your current activity from which your calling the function then it is fine if not then it needs changing.

Also i am not sure what this code is for

        private void startActivity(Intent intent) {

    }

A stack trace would be helpful

Tony
  • 19
  • 1
  • 1
  • 6
  • Honestly I'm not sure whether ListDataAdapter is classes as an activity because it doesn't have an XML file attached to it. it is called from an activity called DataListActivity because its the adapter for the listView. that code is there because when I first typed the code the whole intent was underlined and when I pressed the light bulb it inserted that code, now it only underlines whats in the brackets saying "cannot resolve constructor" . also I'm not too sure what you mean by a stack trace? – krisC Mar 19 '16 at 21:45
  • As far as i am aware the startActivity function is not needed, and ListDataAdapter.this should be the name of the activity from which you wish to to transition from. So i believe it should be DataListActivity. – Tony Mar 19 '16 at 21:56
  • I have now taken out the startActivity function and changed it to DataListActivity.this and it now underlines the startActivity(intent) and saying "startActivity() in ActivityCompat connot be applied to" and changed to DataListActivity.this saying that "DataListActivity is not an enclosing class" – krisC Mar 19 '16 at 23:25