The NoteBook of EricKong

  BlogJava :: 首页 :: 联系 :: 聚合  :: 管理
  611 Posts :: 1 Stories :: 190 Comments :: 0 Trackbacks
package www.puyufanyi.com;

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

import www.puyufanyi.com.test.Word;

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

public class UIActivity extends ListActivity {

    
private ArrayList<Word> words = new ArrayList<Word>();

    @Override
    
public void onCreate(Bundle savedInstanceState) {
        
super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Word word1 
= new Word("index1""result1");
        Word word2 
= new Word("index2""result2");
        Word word3 
= new Word("index3""result3");
        Word word4 
= new Word("index4""result4");
        Word word5 
= new Word("index5""result5");
        
this.words.add(word1);
        
this.words.add(word2);
        
this.words.add(word3);
        
this.words.add(word4);
        
this.words.add(word5);

        List
<Map<String, Object>> listItems = new ArrayList<Map<String, Object>>();

        
for (int i = 0; i < words.size(); i++) {
            Map
<String, Object> listItem = new HashMap<String, Object>();
            listItem.put(
"Index", words.get(i).getIndex());
            listItem.put(
"Result", words.get(i).getResult());
            listItems.add(listItem);
        }
        SimpleAdapter simpleAdapter 
= new SimpleAdapter(
                
this
                listItems, 
                R.layout.main,
                
new String[]{"Index","Result"},
                
new int[]{R.id.index,R.id.result}
        );
                setListAdapter(simpleAdapter);
                ListView lv 
= getListView(); 
                lv.setTextFilterEnabled(
true);
                lv.setOnItemClickListener(
new OnItemClickListener() {
                    
public void onItemClick(AdapterView<?> parent, View view,int position, long id) {
                         String  indexValue 
= ((TextView)view.findViewById(R.id.index)).getText().toString();
                         Toast.makeText(getApplicationContext(), indexValue, Toast.LENGTH_SHORT).show();    
                    }  
                });
                
     }
}
posted on 2012-02-29 15:36 Eric_jiang 阅读(219) 评论(0)  编辑  收藏 所属分类: Android

只有注册用户登录后才能发表评论。


网站导航: