在列表视图点击Android-开放新活动 [英] Android- Open new activity on listview clicks

查看:130
本文介绍了在列表视图点击Android-开放新活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试着让这个当我点击我的列表视图特定的项目,它会带我去特定的屏幕。有谁知道如何做到这一点?使用下面这种情况的code林

此外。我试着去做出一个后退按钮出现在列表视图的底部。到目前为止,我只能让它出现在列表视图中的每个条目,帮助将是很大的AP preciated!

 进口android.app.Activity;
进口android.app.ListActivity;
进口android.content.Intent;
进口android.os.Bundle;
进口android.view.View;
进口android.widget.ArrayAdapter;
进口android.widget.ListView;
进口android.widget.Toast;

公共类广告扩展ListActivity {

    / **第一次创建活动时调用。 * /
    公共无效的onCreate(包冰柱){
        super.onCreate(冰柱);
        //创建一个字符串数组,将被投入到我们的ListActivity
        的String []的名称=新的String [] {LINUX,Windows7的,日蚀,的Suse
                Ubuntu的中的Solaris,机器人,iPhone};
        //使用自己的布局和适配器指向包含标签UI元素
        this.setListAdapter(新ArrayAdapter<字符串>(这一点,R.layout.advertise,
                R.id.label,名称));


    }

    @覆盖
    保护无效onListItemClick(ListView的L,视图V,INT位置,长的id){
        super.onListItemClick(L,V,位置ID);
        //获取被点击的项目
        对象o = this.getListAdapter()的getItem(位置)。
        字符串关键字= o.toString();
        Toast.makeText(这一点,你已经选择:+关键字,Toast.LENGTH_LONG)
                。显示();


        {

        }
    }
}
 

解决方案

开始活动这种方式。

 意向意图=新的意图(com.mysite.myapp.SOME_NEW_ACTIVITY);
startActivity(意向);
 

您不必回到 ListView控件按钮硬件后退按钮将这样做。

Im trying to make it so that when i click specific items in my listview, it will take me to specific screens. Does anyone know how to do this? Im using the code below for this

Furthermore. Im trying to make a single back button appear at the bottom of the listview. So far i can only make it appear on every entry in the listview, help would be greatly appreciated!

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();


        {

        } 
    }
}

解决方案

Start Activity this way.

Intent intent = new Intent("com.mysite.myapp.SOME_NEW_ACTIVITY");   
startActivity(intent); 

You don't need back button in the ListView, your hardware 'Back' button will do the same.

这篇关于在列表视图点击Android-开放新活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆