• 20150625_Andriod_02_ListView2_多条目显示_选中


      android listview

      参考地址:

      http://www.cnblogs.com/zhengbeibei/archive/2013/05/14/3078805.html
      http://xys289187120.blog.51cto.com/3361352/657171/
      http://jeyechao.iteye.com/blog/1149127

    ************************************************************************

    package com.example.ht;

    import android.support.v7.app.ActionBarActivity;
    import android.os.Bundle;
    import android.view.Menu;
    import android.view.MenuItem;

    //////////////////////////
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.Map;

    import android.app.ListActivity;
    //import android.os.Bundle;
    import android.view.View;
    import android.widget.AdapterView;
    import android.widget.ListView;
    import android.widget.SimpleAdapter;
    import android.widget.Toast;
    import android.widget.AdapterView.OnItemClickListener;
    //////////////////////////

    //public class Fr_05_view_s2 extends ActionBarActivity {
    public class Fr_05_view_s2 extends ListActivity {
       
      // TitleList -------------
         //////////////////////////
      private String[] mListTitle = { "姓名", "性别", "年龄", "居住地","邮箱"}; 
      private String[] mListStr = { "云樵", "男", "35", "北京", 
             "wuhang@gmail.com" }; 
         ListView mListView = null; 
         ArrayList<Map<String,Object>> mData= new ArrayList<Map<String,Object>>();;
      //////////////////////////   
     
     @Override
     protected void onCreate(Bundle savedInstanceState) {
      //super.onCreate(savedInstanceState);
      //setContentView(R.layout.activity_fr_05_view_s2);
      
      
      mListView = getListView();
          
      int lengh = mListTitle.length;
      for(int i =0; i < lengh; i++) {
          Map<String,Object> item = new HashMap<String,Object>();
          item.put("title", mListTitle[i]);
          item.put("text", mListStr[i]);
          mData.add(item);
      }
      
      SimpleAdapter adapter = new SimpleAdapter(this,mData,android.R.layout.simple_list_item_2,
       new String[]{"title","text"},new int[]{android.R.id.text1,android.R.id.text2});
             setListAdapter(adapter);
            
             mListView.setOnItemClickListener(new OnItemClickListener() {
              @Override
              public void onItemClick(AdapterView<?> adapterView, View view, int position,
               long id) {
           Toast.makeText(Fr_05_view_s2.this,"您选择了标题:" + mListTitle[position] + "内容:"+mListStr[position], Toast.LENGTH_LONG).show();
              }
          });
            
             super.onCreate(savedInstanceState);
     }

     
     @Override
     public boolean onCreateOptionsMenu(Menu menu) {
      // Inflate the menu; this adds items to the action bar if it is present.
      getMenuInflater().inflate(R.menu.fr_05_view_s2, menu);
      return true;
     }

     @Override
     public boolean onOptionsItemSelected(MenuItem item) {
      // Handle action bar item clicks here. The action bar will
      // automatically handle clicks on the Home/Up button, so long
      // as you specify a parent activity in AndroidManifest.xml.
      int id = item.getItemId();
      if (id == R.id.action_settings) {
       return true;
      }
      return super.onOptionsItemSelected(item);
     }
     
     
    }

    ************************************************************************

  • 相关阅读:
    roscore提示“ModuleNotFoundError: No module named 'defusedxml'”的解决。
    Linux下/home/用户名/.local文件
    vscode 使用技巧一-列编辑。
    Ubuntu下安装visual studio code
    第一阶段(七)
    第一阶段(六)
    Python爬取imdb电影数据并存储到mysql数据库
    第一阶段(五)
    第一阶段(四)
    第一阶段(三)
  • 原文地址:https://www.cnblogs.com/hutie1980/p/4600434.html
Copyright © 2020-2023  润新知