我是新手。
我有three activities A,B and C
。
In the activity B
我有listView
项目列表。On click
我要展示的每件商品tem details in the third activity
。工作正常。
但是当点击模拟器中第三个活动的后退按钮时,它显示我的应用程序已停止工作。
我无法重定向到第二项活动。
但from the second activity
我能来back to the first activity
。
如何解决此问题?
在活动C
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display);
Intent intent = getIntent();
Bundle extras = intent.getExtras();
String displayTitle = extras.getString("title");
String displayPrice = extras.getString("price");
String BasicInfo = extras.getString("BasicInfo");
try {
BasicInfoobj = new JSONObject(BasicInfo);
} catch (JSONException e) {
e.printStackTrace();
}
txtTitle = (TextView)findViewById(R.id.display_txtTitle);
txtPrice = (TextView)findViewById(R.id.display_txtPrice);
txtLocation =(TextView)findViewById(R.id.display_txtLocation);
txtTitle.setText(displayTitle);
txtPrice.setText(displayPrice);
}
在活动B中
private class myListAdapter extends ArrayAdapter<Items> {
public myListAdapter()
{
super(ResultActivity.this,R.layout.item_view,itemList);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
String CurrentImage="";
View itemView = convertView;
if(itemView == null)
{
itemView = getLayoutInflater().inflate(R.layout.item_view,parent,false);
}
//populate the list
//find the item to work with
final Items CurrentItem = itemList.get(position);
//fill the view
TextView title =(TextView)itemView.findViewById(R.id.txt_imageTitle);
title.setText(CurrentItem.GetItemTitle());
CurrentImage = CurrentItem.GetImgUrl();
ImageView imageView = (ImageView)itemView.findViewById(R.id.item_icon);
new ImageLoadTask(CurrentImage, imageView).execute();
TextView Price =(TextView)itemView.findViewById(R.id.txt_itemPrice);
Price.setText(CurrentItem.GetPrice());
title.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(ResultActivity.this,DisplayActivity.class);
Bundle extras = new Bundle();
extras.putString("title",CurrentItem.GetItemTitle());
extras.putString("price",CurrentItem.GetPrice());
extras.putString("basicURL",CurrentItem.GetImgUrl());
extras.putString("ImageUrl",CurrentItem.GetImgSuperUrl());
extras.putString("BasicInfo",CurrentItem.GetBasicInfo().toString());
extras.putString("SellerInfo",CurrentItem.GetSellerInfo().toString());
extras.putString("ShippingInfo",CurrentItem.GetShippingInfo().toString());
intent.putExtras(extras);
startActivity(intent);
}
});
return itemView;
//return super.getView(position, convertView, parent);
}
}
答案 0 :(得分:0)
在活动C中添加适当的代码
@Override
public void onBackPressed()
{
super.onBackPressed();
moveTaskToBack(true);
}
试试这个
答案 1 :(得分:0)
将此添加到您的活动中。
@Override
public void onBackPressed()
{
super.onBackPressed();
finish();
}
答案 2 :(得分:0)
*更正您的代码并添加此代码以控制后退:- *
@override
public void onBackPressed(){
super.onBackPressed();
finish();
}