java Android Activity + onItemClicker(示例)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java Android Activity + onItemClicker(示例)相关的知识,希望对你有一定的参考价值。

public class EarthquakeActivity extends AppCompatActivity {

    public static final String LOG_TAG = EarthquakeActivity.class.getName();

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

        // Create a fake list of earthquake locations.
//        ArrayList<String> earthquakes = new ArrayList<>();
//        earthquakes.add("San Francisco");
//        earthquakes.add("London");
//        earthquakes.add("Tokyo");
//        earthquakes.add("Mexico City");
//        earthquakes.add("Moscow");
//        earthquakes.add("Rio de Janeiro");
//        earthquakes.add("Paris");

//        ArrayList<Earthquake> earthquakes = new ArrayList<Earthquake>();
//        earthquakes.add(new Earthquake("6.2", "London", "22/11/2012"));
//        earthquakes.add(new Earthquake("2.6", "New York", "14/11/2011"));
//        earthquakes.add(new Earthquake("3.3", "Boston", "12/11/2013"));
//        earthquakes.add(new Earthquake("2.7", "Madrid", "26/11/2015"));
//        earthquakes.add(new Earthquake("1.8", "Chicago", "14/11/2010"));

        ArrayList<Earthquake> earthquakes = QueryUtils.extractEarthquakes();

        // Find a reference to the {@link ListView} in the layout
        ListView earthquakeListView = (ListView) findViewById(R.id.list);

        // Create a new {@link ArrayAdapter} of earthquakes
//        ArrayAdapter<String> adapter = new ArrayAdapter<String>(
//                this, android.R.layout.simple_list_item_1, earthquakes);

        final EarthQuakeAdapter earthAdapter = new EarthQuakeAdapter(this, earthquakes);

        // Set the adapter on the {@link ListView}
        // so the list can be populated in the user interface
        earthquakeListView.setAdapter(earthAdapter);

        earthquakeListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                Earthquake currentEarthquake = earthAdapter.getItem(i);
                Uri earthquakeUri = Uri.parse(currentEarthquake.getUrl());
                Intent websiteIntent = new Intent(Intent.ACTION_VIEW, earthquakeUri);
                startActivity(websiteIntent);
            }
        });
    }
}

以上是关于java Android Activity + onItemClicker(示例)的主要内容,如果未能解决你的问题,请参考以下文章

main_activity java 文件的错误消息

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ex.activity/com.ex.activity.L

android activity声明周期学习笔记

阿里Andorid研发一面:小姑娘挺不错来给我先讲讲Fragment和Activity相关吧

Android课程---Activity中保存和恢复用户状态

Android把activity设置为窗口样式怎么去掉标题