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.Activity;
          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 Activity{

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

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

                  ListView lv
          = (ListView)findViewById(R.id.wordlist);
                   
                  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.words,
                          
          new String[]{"Index","Result"},
                          
          new int[]{R.id.index,R.id.result}
                  );
                  lv.setAdapter(simpleAdapter);
                  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();    
                      }
            
                  }
          );
                  
                       
               }

          }

          main.xml

          <?xml version="1.0" encoding="utf-8"?>
          <LinearLayout xmlns:android="    android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:orientation="vertical" >

              <!-- ListView (words) -->

              <ListView
                  android:id="@+id/wordlist"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content" >
              </ListView>

          </LinearLayout>

          words.xml

          <?xml version="1.0" encoding="utf-8"?>
          <LinearLayout xmlns:android="
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:orientation="horizontal" >

              <TextView
                  android:id="@+id/index"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:paddingLeft="10dp" />

              <TextView
                  android:id="@+id/result"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:paddingLeft="10dp" />

          </LinearLayout>








          Feedback

          # Portuguese Translation Studio 2012-03-12 16:34 葡語翻譯公司
          http://www.cnblogs.com/salam/archive/2010/11/15/1877512.html  回復  更多評論
            

          主站蜘蛛池模板: 衡山县| 邛崃市| 禹州市| 安国市| 治多县| 景德镇市| 利津县| 灵川县| 临夏县| 乾安县| 长垣县| 杂多县| 景东| 新疆| 抚顺县| 乌兰察布市| 年辖:市辖区| 漠河县| 罗田县| 高淳县| 临西县| 清原| 黔西县| 景德镇市| 富锦市| 喀喇| 盱眙县| 织金县| 义马市| 山阴县| 雅江县| 葫芦岛市| 达孜县| 门头沟区| 聂荣县| 册亨县| 那曲县| 攀枝花市| 岚皋县| 班玛县| 应用必备|