我已经创建了自定义列表视图,其中包含文本视图列表和按钮列表。现在它显示按钮列表但它没有显示文本视图列表。我有来自 sdcard 内容的文本视图列表。
public class Downloadlist extends ListActivity {
Bundle bundle=null;
private List<String> item = null;
private List<String> path = null;
private String root="/sdcard/mydownloads";
private TextView myPath;
private OrderAdapter m_adapter;
Button b1;
ListView lv1;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mydownload);
bundle = new Bundle();
myPath = (TextView)findViewById(R.id.path);
b1=(Button)findViewById(R.id.view);
lv1=(ListView)findViewById(R.id.list);
getDir(root);
}
private void getDir(String dirPath)
{
myPath.setText("Location: " + dirPath);
item = new ArrayList<String>();
path = new ArrayList<String>();
File f = new File(dirPath);
File[] files = f.listFiles();
if(!dirPath.equals(root))
{
item.add(root);
path.add(root);
item.add("../");
path.add(f.getParent());
}
for(int i=0; i < files.length; i++)
{
File file = files[i];
path.add(file.getPath());
if(file.isDirectory())
item.add(file.getName() + "/");
else
item.add(file.getName());
}
Log.d("itemssssssss", item.toString());
/*ArrayAdapter<String> fileList =
new ArrayAdapter<String>(this,R.id.rowtext, this.item);
setListAdapter(fileList);*/
this.m_adapter = new OrderAdapter(this,R.layout.rowmydownload, item);
setListAdapter(this.m_adapter);
}
@SuppressWarnings("rawtypes")
private class OrderAdapter extends ArrayAdapter {
private List<String> item;
TextView tt=null;
Button bt=null;
ViewHolder holder = null;
@SuppressWarnings("unchecked")
public OrderAdapter(Context context, int textViewResourceId, List<String> items) {
super(context, textViewResourceId, items);
item = items;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
View v = convertView;
if (convertView == null) {
LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.rowmydownload, null);
holder = new ViewHolder();
}
if (item.get(position) != null) {
tt = (TextView) v.findViewById(R.id.rowtext);
Button bt = (Button) v.findViewById(R.id.view);
final String result=item.get(position);
tt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getBaseContext(), "text is clicked"+item.get(position).toString(), Toast.LENGTH_LONG).show();
tt.setText(result.toString());
bundle.putString("listresultfromsd", result);
Intent i1=new Intent(Downloadlist.this,ReadXml.class);
i1.putExtras(bundle);
startActivityForResult(i1,0);
Log.d("resulttttt",result);
}
});
bt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getBaseContext(), "button clicked", Toast.LENGTH_LONG).show();
bundle.putString("listresultfromsd", result);
String strbundle=bundle.toString();
Log.d("bundleeeeeeeee",result);
if(strbundle.contains(".zip"))
{
Intent i2=new Intent(Downloadlist.this,LaunchZip.class);
i2.putExtras(bundle);
startActivityForResult(i2,0);
}
else
{
Intent i3=new Intent(Downloadlist.this,Launch.class);
i3.putExtras(bundle);
startActivityForResult(i3,0);
}
}
});
}
return v;
}
}
}