さて、何が起きているのかわかりません。私は多くのSO「答え」を経験しましたが、結果はありませんでした。リストビューでカスタム アダプターを実行しています。リスト項目をクリックして「もっと見る」ことができるようにしたいのですが、クリックして登録することさえできません。
ここに私の活動があります:
import java.util.ArrayList;
import java.util.List;
import android.app.ProgressDialog;
import android.content.Context;
import android.os.Bundle;
import android.text.method.LinkMovementMethod;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import com.actionbarsherlock.app.SherlockActivity;
import com.androidquery.AQuery;
import com.androidquery.callback.AjaxStatus;
import com.androidquery.util.XmlDom;
public class MainActivity extends SherlockActivity {
private AQuery aq;
private ProgressDialog dialog;
private static final String TAG = "INCIWEB";
private ListView lv;
protected Object IncidentAdapter;
EditText inputSearch;
String url;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setContentView(R.layout.activity_main);
getSupportActionBar().setSubtitle("Incidents across the USA");
aq = new AQuery(this);
dialog = new ProgressDialog(this);
dialog.setCancelable(true);
dialog.setInverseBackgroundForced(false);
dialog.setCanceledOnTouchOutside(true);
dialog.setMessage("Fetching Latest...");
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this, R.array.USStates, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
Spinner s = (Spinner) findViewById(R.id.stateSpinner);
s.setAdapter(adapter);
s.setPrompt("Select a location...");
final String USStates = s.getSelectedItem().toString();
Log.e("STATE", USStates);
s.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parentView,
View selectedItemView, int position, long id) {
try {
getFeed(position);
} catch (Exception e) {
Log.e(TAG, e.getMessage());
}
}
@Override
public void onNothingSelected(AdapterView<?> parentView) {
}
});
}
public void getFeed(int num) {
if (num == 0) {
// latest updates - front page
url = "http://inciweb.org/feeds/rss/incidents/";
} else {
// states
url = "http://inciweb.org/feeds/rss/incidents/state/" + num + "/";
}
Log.e("URL", url);
long expire = -1;
aq.progress(dialog).ajax(url, XmlDom.class, expire, this,
"getFeedCallback");
}
public void getFeedCallback(String url, XmlDom xml, AjaxStatus status) {
List<XmlDom> entries = xml.tags("item");
List<Incidents> incidents = new ArrayList<Incidents>();
for (XmlDom entry : entries) {
incidents.add(new Incidents(entry.text("title"),
entry.text("link"), entry.text("description"), entry
.text("published"), entry.text("geo:lat"), entry
.text("geo:long"), entry.text("georss:point")));
}
lv = (ListView) findViewById(R.id.list);
lv.setTextFilterEnabled(true);
lv.setAdapter(new IncidentAdapter(this,
android.R.layout.simple_list_item_1, incidents));
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View view,
int position, long id) {
Toast.makeText(MainActivity.this, id + "' was clicked.",
Toast.LENGTH_LONG).show();
}
});
}
private class IncidentAdapter extends ArrayAdapter<Incidents> {
private List<Incidents> items;
public IncidentAdapter(Context context, int textViewResourceId,
List<Incidents> items) {
super(context, textViewResourceId, items);
this.items = items;
}
// Create a title and detail
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.incidents_item, null);
}
Incidents o = items.get(position);
if (o != null) {
TextView title = (TextView) v.findViewById(R.id.title);
TextView published = (TextView) v.findViewById(R.id.published);
TextView link = (TextView) v.findViewById(R.id.link);
link.setMovementMethod(LinkMovementMethod.getInstance());
TextView description = (TextView) v
.findViewById(R.id.description);
TextView geoLat = (TextView) v.findViewById(R.id.geoLat);
TextView geoLon = (TextView) v.findViewById(R.id.geoLon);
TextView geoLatLon = (TextView) v.findViewById(R.id.geoLatLon);
if (title != null) {
title.setText(o.getTitle());
}
if (published != null) {
published.setText(o.getPublished());
}
if (link != null) {
link.setText(o.getLink());
}
if (description != null) {
description.setText(o.getDescription());
}
if (geoLat != null) {
geoLat.setText(o.getGeoLat());
}
if (geoLon != null) {
geoLon.setText(o.getGeoLon());
}
if (geoLatLon != null) {
geoLatLon.setText(o.getGeoLatLon());
}
}
return v;
}
}
}
私は何が欠けていますか?
編集:
ここに私のXMLファイルがあります...
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<Spinner
android:id="@+id/stateSpinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/inputSearch" />
<ListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/stateSpinner" />
</RelativeLayout>
件名.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:textSize="20sp" />
<TextView
android:id="@+id/published"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical" />
<TextView
android:id="@+id/link"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical" />
<TextView
android:id="@+id/description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical" />
<TextView
android:id="@+id/geoLat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical" />
<TextView
android:id="@+id/geoLon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical" />
<TextView
android:id="@+id/geoLatLon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical" />
</LinearLayout>
</LinearLayout>
編集:
私がやりたいのは、XML からタイトルを表示してから、リストビューから XML タイトルの onClick で他の XML フィールドを表示することです...