android - 我能对 Intents 和 List View 做些什么

标签 android eclipse

我正在尝试使用 android eclipse 创建一个地点列表,但突然我仍然不明白如何创建一个 Intent ,但我已经使用 ListView 创建了一个列表。

我仍然不明白这些 Intent 是如何工作的,但据我所知,当你在 ListView 中单击某些内容后,它会显示一个新的表单或选项卡

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    populateListView();

}

private void populateListView(){
    String[] myItems = {"Mabuhay" , "Mamatid" , "Banlic"  , "San Isidro" , "Pulo" , 
            "Banay-Banay" , "Dita" , "Sala" , "Bigaa" , "Newgan" , "Butong" , "Marinig" , "Gulod" , 
            "Baclaran"};


    ArrayAdapter<String> adapter = new ArrayAdapter<String>
    (this,R.layout.da_item,myItems);

    ListView list = (ListView) findViewById(R.id.listViewMain);
    list.setAdapter(adapter);
}

我希望我的数组中的那些列表将以运行状态显示,之后我可以单击任何这些列表项,单击它后将显示一个新表单,上面有文本,我也可以返回列表在看到列表中的内容之后。

最佳答案

 list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Intent intent = new Intent(getApplicationContext(),yournewactivity.class);
            intent.putExtra("name",myItems [i]);
            startActivity(intent);
            // OR
            // here you can do what you need 
    }
});

希望对您有所帮助。

关于android - 我能对 Intents 和 List View 做些什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54407082/

相关文章:

android - 在 Google Maps api v2 中设置自定义 InfoWindow 的宽度

linux - Eclipse 在首次启动时锁定 PC

android - Eclipse 中 Android 项目中的自定义源、资源和 AndroidManifest 位置

java - Eclipse 通过更新 pom 修复项目设置?

android - 是否可以在 local.properties 中加载 ANDROID_HOME 值?

eclipse - 需要帮助使用 Eclipse 配置外部差异

java.util.zip.ZipOutputStream - 更快地压缩大文件?

android - 如何接收客户端发送过来的数据

android - 滚动 ListView 时有些图像非常滞后

android - 如何在 android 中设置我的应用程序设备管理员?