【发布时间】:2016-08-15 20:22:31
【问题描述】:
我见过几个在 ListView 上实现的 SwipeView 示例 (here),但这些示例适用于列表中的单个项目,而不适用于 ListView 本身。
在我的应用程序中,意图从一个 Listview 项目开始,并将您发送到相关的 Listview。从那里,我想实现某种功能,允许我从一个 ListView 滑动到另一个。在这种情况下,始终根据意图向下钻取不会像 SwipeView 那样提供用户友好的体验。
如果我没有解释清楚,请告诉我。如果我必须创建额外的类和 XML 布局文件来执行此操作,那就这样吧。
CustomListAdapter.java(保存 ListView 代码的类)
public class CustomListAdapter extends ArrayAdapter<String> {
private Context mContext;
private int id;
private ArrayList<String> callData;
private String[] headers = {"Number", "Customer Number", "Name", "Bill to Customer Number", "Bill to Name",
"Order Date", "Order Time", "Response Date", "Response Time", "Fix by Date", "Fix by Time",
"Responded Date", "Responded Time", "Fixed Date", "Fixed Time", "Your Reference",
"Description", "Transaction Status", "Ship to Code", "Ship to Name", "Ship to Address",
"Ship to Address 2", "Ship to City", "Ship to County", "Ship to Postcode", "Contact Name",
"Phone Number", "Note", "Sources"};
public CustomListAdapter(Context context, int textViewResourceId, ArrayList<String> callData) {
super(context, textViewResourceId, callData);
this.callData = callData;
}
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
if (view == null) {
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.list_service_order, null);
}
String test = callData.get(position);
if (test != null) {
TextView customerNoLabel = (TextView) view.findViewById(R.id.name_label);
TextView customerNoData = (TextView) view.findViewById(R.id.listed_data);
if (customerNoLabel != null) {
customerNoLabel.setText(headers[position]);
customerNoData.setText(callData.get(position));
}
}
return view;
}
}
CallActivity2.java(实现 CustomListAdapter 代码的类,我想用它滑动到具有不同标题和值的两个不同列表视图)
public class CallActivity2 extends ListActivity {
private ArrayList<String> individualCallData;
// private ArrayAdapter<String> callDataAdapter;
private CustomListAdapter callDataAdapter;
private ListView callDataView;
private Runnable viewParts;
private TextView serviceOrderNo;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.call_display);
Intent intent = getIntent();
individualCallData = intent.getStringArrayListExtra("Call");
// Instantiate CustomListAdapter class
callDataView = (ListView) findViewById(android.R.id.list);
callDataAdapter = new CustomListAdapter(this, R.layout.list_service_order, individualCallData);
setListAdapter(callDataAdapter);
viewParts = new Runnable(){
public void run(){
handler.sendEmptyMessage(0);
}
};
// here we call the thread we just defined - it is sent to the handler below.
Thread thread = new Thread(null, viewParts, "MagentoBackground");
thread.start();
}
private Handler handler = new Handler() {
public void handleMessage(Message msg)
{
// create some objects
// here is where you could also request data from a server
// and then create objects from that data.
//individualCallData.add("Test");
callDataAdapter = new CustomListAdapter(CallActivity2.this, R.layout.list_service_order, individualCallData);
// display the list.
setListAdapter(callDataAdapter);
}
};
}
【问题讨论】:
-
这两个列表是否在主列表和详细列表之间滑动(即第一个列表中的列表项是否与其自己的列表相对应)?还是这两个列表不相关?
标签: java android listview swipeview