我是新來的android開發,我正在做我的最後一年項目。在我的項目中,我想執行搜索操作。從數據庫中搜索並以列表視圖顯示,因此可能有多個結果。所以我想設置它的點擊監聽器。但每件事情都在工作,但當我試圖點擊列表視圖結果。它沒有工作..請給我一些建議或任何指導。我已經搜索了與我的問題有關的所有帖子,但沒有解決。請 這裏是我的Java代碼和方法SeeProfile OnClick事件設置從數據庫獲得價值,並在列表視圖中顯示並設置點擊監聽器
public class DisplaySearchResults extends ActionBarActivity {
String json_string, json_string2;
JSONObject jsonObject, JsonObject2;
JSONArray jsonArray, jsonArray2;
AdapterSearchElements adapterSearchElements;
ListView listView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display_search_results);
listView = (ListView) findViewById(R.id.listviewsearch);
listView.setAdapter(adapterSearchElements);
adapterSearchElements = new AdapterSearchElements(this, R.layout.searchresultcutomrow);
listView.setAdapter(adapterSearchElements);
json_string = getIntent().getExtras().getString("json_data");
try {
jsonObject = new JSONObject(json_string);
jsonArray = jsonObject.getJSONArray("server_response");
int count = 0;
String name, Gender, address;
while (count < jsonArray.length()) {
JSONObject JO = jsonArray.getJSONObject(count);
name = JO.getString("name");
Gender = JO.getString("Gender");
address = JO.getString("address");
SearchResultsElements searchResultsElements = new SearchResultsElements(name, Gender, address);
adapterSearchElements.add(searchResultsElements);
count++;
}
} catch (JSONException e) {
e.printStackTrace();
}
}
public void SeeProfile(View view){
json_string2 = getIntent().getExtras().getString("json_data");
Intent i = new Intent(DisplaySearchResults.this, FriendsProfile.class);
i.putExtra("json_data", json_string2);
startActivity(i);
}
}
謝謝@Faruk託普塔斯它會對我有幫助 – Bebo