J'ai trouvé ma réponse dans mon post récent mais maintenant quelque chose gagne en focus de ma liste, donc quand j'essaie de cliquer sur un élément de la liste que je veux sélectionner, rien ne se passe. J'avais fait quelques recherches et appris que quelque chose met l'accent sur l'activité quand cela se produit et la seule chose à laquelle je peux penser est que c'est ma scollview. J'ai essayé de mettre android:focusable="false">
dans mon fichier xml sous mon scrollview mais j'ai toujours les mêmes résultats. Donc, je suis juste en espérant que quelqu'un peut me donner quelques conseilssetOnClickListener ne répond pas
ListActivity:
public class List extends ListActivity {
ArrayList<HashMap<String, String>> questionList;
final String TAG_RESULTS = "results";
static final String TAG_QUESTION_SUBJECT = "Subject";
final String TAG_QUESTION_NUMANSWERS = "NumAnswers";
final String TAG_QUESTION = "question";
final String TAG_QUESTION_CONTENT = "Content";
final String TAG_QUESTION_CHOSENANSWER = "ChosenAnswer";
final String TAG_ANSWERS = "Answers";
final String TAG_ANSWER = "Answer";
final String TAG_ANSWERS_CONTENT = "content";
final String TAG_QUERY = "query";
JSONArray question = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.listview);
questionList = new ArrayList<HashMap<String, String>>();
new LoadAllData().execute();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == 100) {
Intent intent = getIntent();
startActivity(intent);
finish();
}
}
class LoadAllData extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
ProgressDialog pDialog;
pDialog = new ProgressDialog(ListView.this);
pDialog.setMessage("Loading Data. Please wait...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
if (pDialog != null && pDialog.isShowing()) pDialog.dismiss();
}
protected String doInBackground(String... args) {
try {
Intent in = getIntent();
String searchTerm = in.getStringExtra("TAG_SEARCH");
String query = URLEncoder.encode(searchTerm, "utf-8");
String URL = "http://answers.yahooapis.com/AnswersService/V1/questionSearch?appid=4vCW8F3V34GzdMlXOS.yc2WfF5DCnCgqhK0nwCJmEFDgRwEbIgnAoEgJ0zynqOAWtQ&query="+ query +"&search_in=question&sort=relevance&results=25&output=json";
JSONParsser jParser = new JSONParsser();
JSONObject json = jParser.readJSONFeed(URL);
try {
//question = json.getJSONArray(TAG_QUESTION);
JSONArray questions = json.getJSONObject("all").getJSONArray("questions");
for(int i = 0; i < questions.length(); i++) {
JSONObject question = questions.getJSONObject(i);
String Subject = question.getString(TAG_QUESTION_SUBJECT);
String NumAnswers = question.getString(TAG_QUESTION_NUMANSWERS);
String ChosenAnswer = question.getString(TAG_QUESTION_CHOSENANSWER);
String Content = question.getString(TAG_QUESTION_CONTENT);
//JSONArray Answers = question.getJSONObject(TAG_ANSWERS).getJSONArray(TAG_ANSWER);
//JSONObject Answer = Answers.getJSONObject(0);
//String Content = Answer.getString(TAG_ANSWERS_CONTENT);
HashMap<String, String> map = new HashMap<String, String>();
map.put(TAG_QUESTION_SUBJECT, Subject);
map.put(TAG_QUESTION_NUMANSWERS, NumAnswers);
questionList.add(map);
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return TAG_QUESTION ;
}
protected void onPostExecute(String file_URL) {
ListAdapter adapter = new SimpleAdapter(getBaseContext(), questionList,
R.layout.listview,
new String[] { TAG_QUESTION_SUBJECT, TAG_QUESTION_NUMANSWERS }, new int[] {
R.id.Subject, R.id.NumAnswers });
setListAdapter(adapter);
android.widget.ListView lv = getListView();
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
String Subject = ((TextView) findViewById(R.id.Subject)).getText().toString();
String Content = ((TextView) findViewById(R.id.Content)).getText().toString();
String ChosenAnswer = ((TextView) findViewById(R.id.ChosenAnswer)).getText().toString();
Intent i = new Intent(ListView.this, SingleListItem.class);
i.putExtra("TAG_QUESTION_SUBJECT", Subject);
i.putExtra("TAG_QUESTION_CONTENT", Content);
i.putExtra("TAG_QUESTION_CHOSENANSWER", ChosenAnswer);
startActivity(i);
}
});
}}
}
list.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/Subject"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/NumAnswers"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/ChosenAnswer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/Content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="false">
</ScrollView>
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
Essayez de mettre votre écouteur dans une variable avant de les ajouter à la liste. comme OnClickListener listener = new OnClickListener() {}; list.addOnClickListener (écouteur). Parce que l'écouteur inline comme vous l'avez fait peut être ramassé au début;) –
Dites-moi quand cela a fonctionné. Puis-je l'ajouter comme réponse –
Où pensez-vous que le bon endroit pour mettre cette ligne de code –