跟踪按钮单击服务器的列表视图。 Android-Java

时间:2017-04-30 02:49:19

标签: java php android json

我正在使用AsyncResponse从服务器上托管的数据库中获取数据。我将这些数据用作列表视图中可点击的场所。在用户点击场地后,它将引导他们到VenueID指向的场地页面。我的问题是,点击哪个场地以及如何将该信息传递到另一个将显示场地页面活动的班级的最佳方法是什么?对此问题的任何帮助将不胜感激。

干杯

public class MainMenu extends AppCompatActivity implements AsyncResponse {
private ArrayList<GetVenue> venuelist;
private ListView lvVenue;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main_menu);
    Button mapButton = (Button) findViewById(R.id.location);
    PostResponseAsyncTask taskRead = new PostResponseAsyncTask(MainMenu.this, this);
    taskRead.execute("my url");

    //Map button - open map page
    mapButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            startActivity(new Intent(MainMenu.this, MapActivity.class));
        }
    });
}

public void OnClickVenue (View view){
  //  Toast.makeText(getApplicationContext(),name,Toast.LENGTH_LONG).show();

    Intent appInfo = new Intent(MainMenu.this, VenueActivity.class);
    startActivity(appInfo);
}
@Override
public void processFinish(String s) {

    venuelist = new JsonConverter<GetVenue>().toArrayList(s, GetVenue.class);

    final BindDictionary<GetVenue> dict = new BindDictionary<GetVenue>();
/*    dict.addStringField(R.id.VenueID, new StringExtractor<GetVenue>(){
        @Override
        public String getStringValue(GetVenue venue, int position){
            return "" + venue.VenueID;
        }
   });*/

    dict.addStringField(R.id.VenueName, new StringExtractor<GetVenue>() {
        @Override
        public String getStringValue(GetVenue venue, int position) {
            return venue.VenueName;
        }
    });
  /*  dict.addStringField(R.id.Phone, new StringExtractor<GetVenue>() {
        @Override
        public String getStringValue(GetVenue venue, int position) {
            return venue.Phone;
        }
    });*/


    FunDapter<GetVenue> adapter = new FunDapter<>
            (MainMenu.this, venuelist, R.layout.layout_main, dict);

    lvVenue = (ListView) findViewById(R.id.lvVenue);
    lvVenue.setAdapter(adapter);



 /* On click of venue String, open Venue page*/

    lvVenue.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view,
                                int position, long id) {
            Intent appInfo = new Intent(MainMenu.this, VenueActivity.class);
            startActivity(appInfo);
        }
    });
}

}

1 个答案:

答案 0 :(得分:0)

OnItemClick api返回基于您将通过使用list api get(position)获得所选项目而单击的项目的位置。

extern m_p H;

m_p func2(int s) {

  int n_s = ALIGN(s);
    m_p p = H;

    while(p != NULL ){
        printf("1. %d \n", p->data);
        p = p->next; //this is always NULL even if there were more than one node previously in func()
        if(p == NULL) printf("LINK NOT PRESENT \n");    
    }

  /* ... */

}

GetVenue getVenue = venuelist.get(position);