20150625_Andriod_01_ListView1_条目选中

时间:2023-01-05 19:23:50

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 android.view.View;
//////////////////////////////////
import android.app.ListActivity;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.os.Bundle;

import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView;

//////////////////////////////////

public class Fr_02_view_s1 extends ActionBarActivity {
    //////////////////////////////////
 private ListView mListView = null;
 private ArrayAdapter myAdapter = null;
 
 private String str_1;
    //////////////////////////////////
 
 private  static String[] db_string=null;
 private  static final String[] COUNTRIES=new String[]{"中国","俄罗斯","英国","法国","中国","俄罗斯","英国","法国"};
 
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_fr_02_view_s1);
  
        /////////------/////////
  Bundle bunde = this.getIntent().getExtras();
  str_1 = bunde.getString("key_view_s1").toString();
  db_string =str_1.split(",");
        /////////------/////////
  
  //setContentView(R.layout.main); 
        //设置一个Adapter 
  mListView = (ListView) findViewById(R.id.listView1);//得到ListView对象的引用 /*为ListView设置Adapter来绑定数据*/

// mListView.setAdapter(new ArrayAdapter<String>(this,
   //               android.R.layout.simple_expandable_list_item_1, COUNTRIES));
  
  mListView.setAdapter(new ArrayAdapter<String>(this,
                    android.R.layout.simple_expandable_list_item_1, db_string));
  
       
  ///////////////////条目选中///////////////////
        ///////////////////
  mListView.setOnItemClickListener(new OnItemClickListener() { 
         @Override 
         public void onItemClick(AdapterView<?> adapterView, View view, int position, 
             long id) { 
         Toast.makeText(Fr_02_view_s1.this,"您选择了" + db_string[position], Toast.LENGTH_LONG).show(); 
         } 
     }); 
  ///////////////////

}
 
 @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_02_view_s1, 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);
 }

}

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