6
我试图让它在我点击我的列表视图中的特定项时,会带我到特定的屏幕。有谁知道如何做到这一点?我使用下面的代码为此Android-在列表视图上打开新活动点击
此外。我试图让一个单一的后退按钮出现在列表视图的底部。到目前为止,我只能让它出现在列表视图中的每一个条目,帮助将不胜感激!
import android.app.Activity;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
public class Advertise extends ListActivity {
/** Called when the activity is first created. */
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
// Create an array of Strings, that will be put to our ListActivity
String[] names = new String[] { "Linux", "Windows7", "Eclipse", "Suse",
"Ubuntu", "Solaris", "Android", "iPhone" };
// Use your own layout and point the adapter to the UI elements which contains the label
this.setListAdapter(new ArrayAdapter<String>(this, R.layout.advertise,
R.id.label, names));
}
@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();
Toast.makeText(this, "You selected: " + keyword, Toast.LENGTH_LONG)
.show();
{
}
}
}
你知道如何开始一项活动吗?什么后退按钮?你不会显示关于后退按钮的任何信息。 – Falmarri 2011-01-11 22:17:51
我没有添加后退按钮代码抱歉。它在xml中。但我已经为我的正常屏幕创建了它们。我一直在使用Button sell =(Button)findViewById(R.id.sell); \t \t sell.setOnClickListener(新View.OnClickListener(){ \t \t \t公共无效的onClick(查看视图){ \t \t \t \t意图myIntent =新意图(view.getContext(),Sell.class); \t \t \t \t \t startActivity(myIntent); – James 2011-01-11 22:27:07