java微信企業號開辟之發送新聞(文本、圖片、語音)。本站提示廣大學習愛好者:(java微信企業號開辟之發送新聞(文本、圖片、語音))文章只能為提供參考,不一定能成為您想要的結果。以下是java微信企業號開辟之發送新聞(文本、圖片、語音)正文
本文實例講述了Android完成的ListView分組結構改良辦法。分享給年夜家供年夜家參考,詳細以下:
因為是在網上轉載的一篇文章,在這裡就不多說空話了,起首看一下終究的後果圖:
然後是完成該ListView結構的重要代碼:
1、法式主界面 SeparateListView.java
package whu.iss.wuxianglong; import java.util.ArrayList; import java.util.List; import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.TextView; public class SeparateListView extends Activity { ListView listView; MyAdapter myAdapter; public List<String> listTag = new ArrayList<String>(); /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); listView = (ListView) findViewById(R.id.list); myAdapter = new MyAdapter(this, android.R.layout.simple_expandable_list_item_1, getData()); listView.setAdapter(myAdapter); } private List<String> getData() { List<String> data = new ArrayList<String>(); int i = 0; data.add("A"); listTag.add("A"); data.add("aa試數據" + (i++)); data.add("a試數據" + (i++)); data.add("aa試數據" + (i++)); listTag.add("B"); data.add("B"); data.add("bb試數據" + (i++)); data.add("b試數據" + (i++)); data.add("b試數據" + (i++)); data.add("b試數據" + (i++)); listTag.add("C"); data.add("C"); data.add("c測試數據" + (i++)); data.add("c測試數據" + (i++)); listTag.add("D"); data.add("D"); data.add("d測試數據" + (i++)); data.add("d測試數據" + (i++)); data.add("d測試數據" + (i++)); listTag.add("E"); data.add("E"); data.add("e測試數據" + (i++)); data.add("e測試數據" + (i++)); data.add("e測試數據" + (i++)); listTag.add("F"); data.add("F" ); data.add("f測試數據" + (i++)); return data; } class MyAdapter extends ArrayAdapter<String> { public MyAdapter(Context context, int textViewResourceId, List<String> objects) { super(context, textViewResourceId, objects); } @Override public boolean areAllItemsEnabled() { return false; } @Override public boolean isEnabled(int position) { // 假如-開首,則該項弗成選 return !listTag.contains(getItem(position)); } @Override public View getView(int position, View convertView, ViewGroup parent) { View view = convertView; //依據標簽類型加載欠亨的結構模板 if(listTag.contains(getItem(position))){ //假如是標簽項 view = LayoutInflater.from(getContext()).inflate(R.layout.group_list_item_tag, null); }else{ //不然就是數據項 view = LayoutInflater.from(getContext()).inflate(R.layout.group_list_item, null); } //顯示稱號 TextView textView = (TextView) view.findViewById(R.id.group_list_item_text); textView.setText(getItem(position)); //前往重寫的view return view; } } }
2、法式主界面結構文件main.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <ListView android:id="@+id/list" android:layout_width="fill_parent" android:layout_height="wrap_content"> </ListView> </LinearLayout>
3、ListView中數據部門款式結構文件group_list_item.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:padding="5dip"> <ImageView android:src="@drawable/icon" android:layout_width="50px" android:layout_height="50px"> </ImageView> <TextView android:id="@+id/group_list_item_text" android:layout_width="wrap_content" android:layout_height="fill_parent" android:paddingLeft="5dip" android:gravity="center_vertical"> </TextView> </LinearLayout>
4、ListView平分組標記行的款式結構文件group_list_item_tag.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="#555555" android:paddingLeft="10dip"> <TextView android:id="@+id/group_list_item_text" android:layout_width="wrap_content" android:layout_height="20dip" android:textColor="#ffffff" android:gravity="center_vertical"> </TextView> </LinearLayout>
願望本文所述對年夜家Android法式設計有所贊助。