zoukankan      html  css  js  c++  java
  • ListView的简单使用--Android

    1、本例实现效果图

    2、主要是activity_main.xml(布局文件)和Activity类文件,实现过程比较简单,直接附源码了哈!

    activity_main.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="match_parent"
    android:background="@color/color_main_bg">
      <ListView
      android:id="@+id/list_view"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      />
    </RelativeLayout>

    MainActivity.java:

    package livetelecast.thonlon.example.cn.thonlonlivetelecast;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.AdapterView;
    import android.widget.ArrayAdapter;
    import android.widget.ListView;
    import android.widget.Toast;

    public class MainActivity extends AppCompatActivity {
      private ListView listView;
      @Override
      protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        listView=(ListView) findViewById(R.id.list_view);
        final ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,android.R.layout.simple_expandable_list_item_1,getData());
        listView.setAdapter(adapter);// 不关心数据是从哪里来的只需要设置 adapter,adapter会给listview数据
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override //items的点击事件
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
          String txt=adapter.getItem(i);
          // Toast.makeText(MainActivity.this,txt,0).show();
          // setContentView(R.layout.activity_play);
        }
      });
    }
        private String[] getData(){
          return new String[]{"CCTV1","CCTV2","CCTV3","CCTV4","CCTV5","CCTV6","CCTV7","CCTV8","CCTV9","湖南卫视"};
          }
    }

    3、源码下载:ListView.zip

     
     
     
     
  • 相关阅读:
    hdu 1083 Courses
    hdu 1068 Girls and Boys
    hdu 2988 Dark roads
    hdu 1879 继续畅通工程
    hdu 1875 畅通工程再续
    hdu 1233 还是畅通工程
    hdu 4040 (贪心算法)
    FZU 2111 Min Number
    Reconstructing Cloud-Contaminated Multispectral Images With Contextualized Autoencoder Neural Networks(自编码机重建云污染区)
    跑深度学习网络遇到的一些错误总结
  • 原文地址:https://www.cnblogs.com/qikeyishu/p/8973310.html
Copyright © 2011-2022 走看看