???Android???11.0 UI?????????????????????????????????ListView???????????????2
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了???Android???11.0 UI?????????????????????????????????ListView???????????????2相关的知识,希望对你有一定的参考价值。
?????????sha rom ?????? not private ble roi ?????? finish
1.0 ??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????ListView???
2.0 ????????????ListViewTest??????????????????????????????
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);}
//????????????
public static 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 = {
"?????????????????????", "??????????????????", "?????????????????????", "?????????????????????", "????????????????????????", "?????????????????????", "?????????????????????",
"?????????", "?????????", "?????????", "?????????", "?????????", "?????????", "????????????",
"?????????", "?????????", "?????????", "?????????", "?????????",
"?????????", "?????????", "?????????", "?????????", "?????????",
"?????????", "?????????", "?????????", "?????????", "?????????",};
@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++){
// Province province = new Province(data[i]);
// provincelist.add(province);
// }
}
}
10.0 ?????????????????????
以上是关于???Android???11.0 UI?????????????????????????????????ListView???????????????2的主要内容,如果未能解决你的问题,请参考以下文章
更新 xcode 9 和 iOS 11.0 后有人遇到 UI 问题吗?
Swift UI 实时预览画布不适用于 macOS Catalina 和 Xcode 11.0