package com.rfid.demo;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Toast;
import java.util.ArrayList;
public class StocklistActivity extends AppCompatActivity {
/**
* Called when the activity is first created.
*/
private ListView listView;
private ArrayAdapter<String> arrayAdapter;
private SimpleAdapter simpleAdapter;
private ArrayList<String> data;
//新建盘点批次界面
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_stocklist);
listView = (ListView) findViewById(R.id.listviewstock);
//初始化数据
initData();
//创建数组适配器,作为数据源和列表控件联系的桥梁
//第一个参数:上下文环境
//第二个参数:当前列表项加载的布局文件
//第三个参数:数据源
arrayAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,data);
//listview视图加载适配器
listView.setAdapter(arrayAdapter);
//为列表视图中选中的项添加响应事件
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String result = parent.getItemAtPosition(position).toString();//获取选择项的值
Toast.makeText(StocklistActivity.this,"您点击了"+result,Toast.LENGTH_SHORT).show();
}
});
}
private void initData(){
data = new ArrayList<String>();
for (int i=0;i<13;i++){
data.add(+(i+1)+"\t\t"+"20190808"+i+"\t"+"8");
}
}
}
来源:https://blog.csdn.net/baidu_38995168/article/details/99546734