I got 2 classes in my project. The first class(main) have a listview and this is the onclick():
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
// Get the item that was clicked
Object o = this.getListAdapter().getItem(position);
String keyword = o.toString();
class2 sec = new Class2();
Intent intent = new Intent(this, Class2.class);
startActivity(intent) ;
if (keyword == "hello"){
sec.setInfo(keyword);
}
}
so and then in my other class which have a defferent layout.xml. The code is:
public class det extends Activity {
static WebView map;
public TextView header;
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.details);
}
public void setInfo(String mystring){
he开发者_运维问答ader = (TextView) findViewById(R.id.text01);
header.setText(mystring);
//Toast.makeText(this, map, Toast.LENGTH_LONG).show();
//return;
}
Ye, i keep getting force close on my android phone. The App i meant to change the header text to text that ive tapped on the listview. But when i click a item it pop up a window with FC.
ive try to comment away the:
header = (TextView) findViewById(R.id.text01);
header.setText(mystring);
and it worked without a FC however the headertext is stil null.
Thank you! Your Friend!
First of all, you need to post the stack trace for us to have any idea how to help.
Second, I'm assuming Class2
extends Activity or else Intent intent = new Intent(this, Class2.class);
doesn't make any sense. That being the case, class2 sec = new Class2();
is ALWAYS wrong. You never ever call new
on a class that extends Activity.
You can't call methods on another activity like that. Your only real option is to send the keyword in the intent by using putExtra, and then getting retrieving it in Class2
精彩评论