页面布局 ListView 文本输入框

  • Post author:
  • Post category:其他




文本输入框



调用程序

public class MainActivity3 extends AppCompatActivity {

    private ListView lvPlanet;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main3);

        initView();

        ArrayList<String> list = new ArrayList<>();
        list.add("1");
        list.add("2");
        list.add("3");
        lvPlanet.setAdapter(new TextListAdapter(this,list));
    }

    private void initView() {
        lvPlanet = (ListView) findViewById(R.id.lv_planet);
    }
}



文本输入框 Adapter

public class TextListAdapter extends BaseAdapter {
    private static final String TAG = "JJWorld.TextListAdapter";
    private Context mContext;
    private List<String> mTextList;
    private int mCount = 0;

    public TextListAdapter(Context context, ArrayList<String> textList) {
        mContext = context;
        mTextList = textList;
    }


    @Override
    public int getCount() {
        return mTextList.size();
    }

    @Override
    public Object getItem(int position) {
        return mTextList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        mCount++;
        ViewHolder holder;
        if (convertView == null) {
            Log.i(TAG,"convertView is null ---- position:" + position + " mCount:" + mCount);
            holder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.text_list_item,null);
            holder.textView = (TextView) convertView.findViewById(R.id.tv_name);
            convertView.setTag(holder);
        }else {
            Log.i(TAG,"convertView null ---- position:" + position + " mCount:" + mCount);
            holder = (ViewHolder) convertView.getTag();
        }
        holder.textView.setText(mTextList.get(position));
        return convertView;
    }

    private final class ViewHolder{
        public TextView textView;
    }
}



文本输入框 list布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
    android:background = "@color/white"
    android:orientation="horizontal">

    <TextView
        android:id="@+id/tv_name"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:layout_weight="1"
        android:text="提示语"
        android:textColor="@color/black"
        android:textSize="20sp"/>

    <EditText
        android:id="@+id/tv_desc"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:layout_weight="1"
        android:hint="输入内容"
        android:textSize="20sp"
        android:textColor="@color/black"/>

</LinearLayout>



版权声明:本文为qq_42015021原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。