???Android???11.0 UI?????????????????????????????????ListView???????????????2

相逢意气为君饮,系马高楼垂柳边。这篇文章主要讲述???Android???11.0 UI?????????????????????????????????ListView???????????????2相关的知识,希望能为你提供帮助。
?????????sha      rom      ??????      not      private      ble      roi      ??????      finish     
1.0 ??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????ListView???
2.0 ????????????ListViewTest??????????????????????????????
 

???Android???11.0 UI?????????????????????????????????ListView???????????????2

文章图片

 
3.0 ActivityCollector.java
package com.example.listviewtest; import android.app.Activity; import java.util.ArrayList; import java.util.List; public class ActivityCollector { public static List< Activity> activities = new ArrayList< > (); //???????????? public static void addActivity(Activity activity){activities.add(activity); } //???????????? publicstatic void removeActivity(Activity activity){activities.remove(activity); }//??????????????????public static void finishAll(){ for (Activity activity:activities){ if (!activity.isFinishing()){ activity.finish(); } } } }

 
4.0 BaseActivity.java
package com.example.listviewtest; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v7.app.AppCompatActivity; import android.util.Log; public class BaseActivity extends AppCompatActivity { @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.d("BaseActivity:***",getClass().getSimpleName()); ActivityCollector.addActivity(this); }@Override protected void onDestroy() { super.onDestroy(); } }

 
5.0 Province.java
package com.example.listviewtest; public class Province { private String name; public Province(String name){ this.name = name; }public String getName() { return name; } }

 
6.0 ProvinceAdapter.java
package com.example.listviewtest; import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.TextView; import java.util.List; public class ProvinceAdapter extends ArrayAdapter< Province> { private int resourceId; public ProvinceAdapter(Context context, int textViewResourceId, List< Province> objects) { super(context, textViewResourceId, objects); resourceId = textViewResourceId; }@Override public View getView(int position, View convertView, ViewGroup parent) { Province province = getItem(position); //???????????????Province?????? View view = LayoutInflater.from(getContext()).inflate(resourceId, parent, false); TextView provinceName =(TextView) view.findViewById(R.id.province_name); provinceName.setText(province.getName()); return view; } }

 
7.0 activity_main.xml
< ?xml version="1.0" encoding="utf-8"?> < android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> < ListView android:id="@+id/list_view" android:layout_width="0dp" android:layout_height="wrap_content"app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="@+id/guideline" /> < android.support.constraint.Guideline android:id="@+id/guideline" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" app:layout_constraintGuide_percent="0.05" /> < /android.support.constraint.ConstraintLayout>

 
8.0 province_item.xml
< ?xml version="1.0" encoding="utf-8"?> < android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent"> < TextView android:id="@+id/province_name" android:layout_width="match_parent" android:layout_height="32dp" android:textSize="18dp" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.0" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> < /android.support.constraint.ConstraintLayout>

 
9.0 MainActivity.java
 
package com.example.listviewtest; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.ListView; import android.widget.Toast; import java.util.ArrayList; import java.util.List; public class MainActivity extends BaseActivity { private List< Province> provincelist = new ArrayList< > (); private String[] data = https://www.songbingjia.com/android/{"?????????????????????", "??????????????????", "?????????????????????", "?????????????????????", "????????????????????????", "?????????????????????", "?????????????????????", "?????????", "?????????", "?????????", "?????????", "?????????", "?????????", "????????????", "?????????", "?????????", "?????????", "?????????", "?????????", "?????????", "?????????", "?????????", "?????????", "?????????", "?????????", "?????????", "?????????", "?????????", "?????????",}; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initProvince(); ProvinceAdapter adapter = new ProvinceAdapter(MainActivity.this, R.layout.province_item, provincelist); ListView listView = (ListView) findViewById(R.id.list_view); listView.setAdapter(adapter); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {@Override public void onItemClick(AdapterView< ?> parent, View view, int position, long id) { Province province = provincelist.get(position); Toast.makeText(MainActivity.this, province.getName(), Toast.LENGTH_SHORT).show(); } }); }public void initProvince() { for (String dataone : data) { Province province = new Province(dataone); provincelist.add(province); } //for (int i = 0; i< data.length; i++){ //Provinceprovince = new Province(data[i]); //provincelist.add(province); //} } }

 
10.0 ?????????????????????
【???Android???11.0 UI?????????????????????????????????ListView???????????????2】 
???Android???11.0 UI?????????????????????????????????ListView???????????????2

文章图片


    推荐阅读