Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Using simplesursoradapter I have raised a listview. I select an item from listview and keep it in a variable 'titlename' and able to show in Toast. Now, I want this value in 'titlename' to be passed to a text view id 'textView3' so that it could be displayed on top of the screen in the same activity. When I tried with the following code I get a NULL pointer exception at line textView.setText(query.toString());


a)TextView ID 'textView' and 'textView2' are in custom_row.xml

b)TextView ID 'textView3' is in Activity_Out.xml


Java
static String v_titlename;

public void onItemClick(AdapterView        TextView selectedTitle = (TextView)view.findViewById(R.id.textView);
        TextView titlename= (TextView)view.findViewById(R.id.textView2);
        TextView textView = (TextView) findViewById(R.id.textView3);
        v_titlename=titlename.getText().toString();
        String query = titlename.getText().toString();
        textView.setText(query.toString());
        Toast.makeText(this, titlename.getText() , Toast.LENGTH_LONG).show();
        inputID=selectedTitle.getText().toString(); // the _id of this title is stored in inputID
    }
Posted
Updated 28-Mar-15 21:31pm
v2
Comments
Peter Leow 29-Mar-15 0:31am    
If seems that the textView3 is not bound to the activity. How did you do it?
S.Rajendran from Coimbatore 29-Mar-15 10:35am    
Well what you said is correct. It should have been textView6.

1 solution

You code does not make sense. Check these out:
1. Android ListView Example[^]
2. Using two layout xml file for one Activity[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900