在列表视图中显示组织列表。使用异步任务通过 url iam 获取列表视图中的组织名称。单击任何组织名称时,每个组织的详细信息都会显示在新活动中。
但是我收到此错误构造函数 ArrayAdapter(Organization.YourDownload, int, int, ArrayList) 未定义。提前致谢
public class Organization extends ListActivity {
XMLGettersSetters data;
private static final int ACTIVITY_CREATE=0;
private static final int ACTIVITY_EDIT=1;
private Context mActivityAContext;
private static Organization _appCtrl;
// private static final int INSERT_ID = Menu.FIRST;
// private static final int DELETE_ID = Menu.FIRST + 1;
private final int MENU_ORG = Menu.FIRST;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Organization._appCtrl = this;
// this.setTitle(R.drawable.add_org);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.drawable.add_org);
// setTitle(R.drawable.add_org);
new YourDownload().execute();
}
class YourDownload extends AsyncTask<Void, Void, Void> {
protected Void doInBackground(Void... params) {
try{
SAXParserFactory saxPF= SAXParserFactory.newInstance();
SAXParser saxP = saxPF.newSAXParser();
XMLReader xmlR = saxP.getXMLReader();
URL url = new URL("http://xyz/get_organization_details");
XMLHandler myXMLHandler = new XMLHandler();
xmlR.setContentHandler(myXMLHandler);
xmlR.parse(new InputSource(url.openStream()));
}catch(Exception e){
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
data= XMLHandler.data;
ListView lv = getListView();
lv.setBackgroundResource(R.drawable.background);
LayoutInflater inflater = getLayoutInflater();
ViewGroup header = (ViewGroup)inflater.inflate(R.layout.header_addorg, lv, false);
lv.addHeaderView(header, null, false);
//Organization.getAppCtrl();
this.setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, R.id.label,data.getName()));
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// selected item
String name = ((TextView)view).getText().toString();
for(int i=0;i<data.getId().size();i++){
if(name.equalsIgnoreCase(data.getName().get(i).toString()))
{
String email = data.getEmail().get(i).toString();
String address=data.getAddress().get(i).toString();
String url=data.getUrl().get(i).toString();
String postcode = data.getPostcode().get(i).toString();
String id_org = data.getId().get(i).toString();
Log.v("ID",id_org.toString());
// Log.v("postcode",postcode.toString());
// Launching new Activity on selecting single List Item
Intent intent = new Intent(getApplicationContext(),SingleListItem.class);
// sending data to new activity
intent.putExtra("name", name);
intent.putExtra("email", email);
intent.putExtra("address", address);
intent.putExtra("url", url);
intent.putExtra("postcode", postcode);
intent.putExtra("id_org", id_org);
startActivity(intent);
}
}
}
});
}
@Override
protected void onPreExecute() {
// pre execute logic
super.onPreExecute();
}
}
public boolean onCreateOptionsMenu(Menu menu) {
menu.add(0, 11, 0, "Add Organization");
return super.onPrepareOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if(item.getItemId() == 11) {
//setCategoryReportValues();
addorgm();
}
return super.onOptionsItemSelected(item);
}
public static Organization getAppCtrl()
{
return _appCtrl;
}
public void setContextForActivityA(Context context)
{
mActivityAContext = context;
}
public Context getContextForActivityA()
{
return mActivityAContext;
}
private void addorgm() {
Intent i = new Intent(Organization.this,AddOrg.class);
startActivity(i);
}
}