0
我想添加自定義適配器,我想補充這是我從網絡服務獲得該特定文件夾的文件夾圖像和名稱。如何使用ArrayAdapter添加自定義適配器?
請看看我的代碼:
ListView listview;
LazyAdapter adapter;
private String[] folderslist;
String User_ID;
int i;
static String ID = "ID";
static String KEY_Name = "FolderName";
static String ParentID = "ParentID";
static String CreatedBy = "CreatedBy";
private static final String NAMESPACE = "http://tempuri.org/";
private static final String URL = "http://***.***.*.*/somethinghere/something.asmx";
private static final String TREEDATA_METHOD = "TreeData";
private static final String SOAP_ACTION_TREEDATA = "http://tempuri.org/TreeData";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.homepage_layout);
Intent Intent = getIntent();
User_ID = Intent.getStringExtra("User_ID");
Treedata();
listview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
String item = (String) listview.getItemAtPosition(position);
ID = item;
Intent mIntent = new Intent(getApplicationContext(), Files_Folders_Activity.class);
mIntent.putExtra("ID", ID);
startActivity(mIntent);
}
});
}
public void Treedata(){
try {
SoapObject datarequest = new SoapObject(NAMESPACE, TREEDATA_METHOD);
datarequest.addProperty("UserID", User_ID);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(datarequest);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.debug = true;
androidHttpTransport.call(SOAP_ACTION_TREEDATA, envelope);
SoapObject folderResponse = (SoapObject)envelope.getResponse();
Log.i("AllFolders", folderResponse.toString());
folderslist = new String[folderResponse.getPropertyCount()];
for(i=0; i<folderResponse.getPropertyCount(); i++) {
SoapObject SingleFolder = (SoapObject)folderResponse.getProperty(i);
Log.i("SingleFolder", SingleFolder.toString());
ID= SingleFolder.getProperty(0).toString();
KEY_Name = SingleFolder.getProperty(1).toString();
ParentID = SingleFolder.getProperty(2).toString();
CreatedBy= SingleFolder.getProperty(3).toString();
folderslist[i] = SingleFolder.getProperty(0).toString();
folderslist = new String[] {ID};
}
data = new ArrayList<FolderList>();
for (int i = 0; i < folderslist.length; i++) {
FolderList item = new FolderList(images[i], folderslist[i]);
data.add(item);
}
listview = (ListView)findViewById(R.id.listview);
LazyAdapter adapter = new LazyAdapter(this, R.layout.jpg_row, data);
listview.setAdapter(adapter);
listview.setOnItemClickListener(this);
}
}
LazyAdapter:
public class LazyAdapter extends ArrayAdapter<FolderList> {
Context context;
public LazyAdapter(Context context, int resourceId, List<FolderList> items) {
super(context, resourceId, items);
this.context = context;
}
/*private view holder class*/
private class ViewHolder {
ImageView imageView;
TextView txtTitle;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
FolderList data = getItem(position);
LayoutInflater mInflater = (LayoutInflater) context
.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = mInflater.inflate(R.layout.jpg_row, null);
holder = new ViewHolder();
holder.txtTitle = (TextView) convertView.findViewById(R.id.txtTitle);
holder.imageView = (ImageView) convertView.findViewById(R.id.imgIcon);
convertView.setTag(holder);
} else
holder = (ViewHolder) convertView.getTag();
holder.txtTitle.setText(data.getTitle());
holder.imageView.setImageResource(data.getIcon());
return convertView;
}
}
我使用的String []來獲得網絡響應,然後財產1的ID文件夾名稱。任何人都可以讓我知道如何添加自定義列表,其中顯示文件夾圖像和文件夾名稱或可以正確引導?由於
我想自定義適配器,列表顯示。問題是,我想使用自定義適配器從Web服務顯示文件夾的文件夾圖像和名稱 – Shweta 2013-02-26 06:24:30
@shiva:我已經編輯我的答案。 – 2013-02-26 06:28:01
我明白了你的意思,但你有沒有看過我的問題? – Shweta 2013-02-26 07:28:01