I'm relatively new to android development but my project was all going fairly well until I hit this problem. I have researched this question but none of the solutions to other questions have fixed my problem.
I have a SportsAvtivity which implements AdapterView OnItemClickListener but nothing is happening when I click on a list item.
Any Help would be greatly appreciated.
SportsActivity.java:
public class SportsActivity extends Activity implements AdapterView.OnItemClickListener {
ListView mainListView;
JSONAdapter mJSONAdapter;
private static final String QUERY_URL = "http://ift.tt/1ellovh";
ProgressDialog mDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sports);
// Access the ListView
mainListView = (ListView) findViewById(R.id.list);
// Set this activity to react to list items being pressed
mainListView.setOnItemClickListener(this);
// Create a JSONAdapter for the ListView
mJSONAdapter = new JSONAdapter(this, getLayoutInflater());
// Set the ListView to use the ArrayAdapter
mainListView.setAdapter(mJSONAdapter);
mDialog = new ProgressDialog(this);
mDialog.setMessage("Searching for Clubs");
mDialog.setCancelable(false);
// Create a client to perform networking
AsyncHttpClient client = new AsyncHttpClient();
// Show ProgressDialog to inform user that a task in the background is occurring
mDialog.show();
// Have the client get a JSONArray of data
// and define how to respond
client.get(QUERY_URL, new JsonHttpResponseHandler() {
@Override
public void onSuccess(JSONObject jsonObject) {
// Dismiss the ProgressDialog
mDialog.dismiss();
// update the data in your custom method.
mJSONAdapter.updateData(jsonObject.optJSONArray("vfss"));
}
@Override
public void onFailure(int statusCode, Throwable throwable, JSONObject error) {
// Dismiss the ProgressDialog
mDialog.dismiss();
// Display a "Toast" message
// to announce the failure
Toast.makeText(getApplicationContext(), "Network error, please close app and try again", Toast.LENGTH_LONG).show();
// Log error message
// to help solve any problems
Log.e("omg android", statusCode + " " + throwable.getMessage());
}
}
);
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// Now that the user's chosen an item, grab the cover data
//JSONObject jsonObject = (JSONObject) mJSONAdapter.getItem(position);
//String clubImage = jsonObject.optString("Image_Path","");
// create an Intent to take you over to a new DetailActivity
Intent clubIntent = new Intent(this, ClubActivity.class);
// pack away the data about the cover
// into your Intent before you head out
//clubIntent.putExtra("clubImage", clubImage);
// start the next Activity using your prepared Intent
startActivity(clubIntent);
}
}
activity_sports.xml:
<LinearLayout xmlns:android="http://ift.tt/nIICcg"
xmlns:tools="http://ift.tt/LrGmb4"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#F1F1F1"
tools:context=".MainActivity" >
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:listitem="@layout/row">
</ListView>
</LinearLayout>
row.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://ift.tt/nIICcg"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="4dp"
android:orientation="vertical"
android:background="#ffffffff">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:orientation="horizontal"
android:showDividers="none"
android:focusable="false"
android:clickable="false">
<ImageView
android:id="@+id/ivImage"
android:layout_width="70dp"
android:layout_height="70dp"
android:src="@mipmap/sports256"
android:layout_gravity="center_vertical"
android:layout_marginLeft="2dp"
android:focusable="false"
android:clickable="false"/>
<TextView
android:id="@+id/tvName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/clubName"
android:layout_weight="0.7"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:textColor="#ff000000"
android:textSize="25sp"
android:maxWidth="80dp"
android:minWidth="80dp"
android:focusable="false"
android:clickable="false"/>
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:src="@mipmap/point"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:layout_weight="0.1"
android:focusable="false"
android:clickable="false"/>
</LinearLayout>
</LinearLayout>
Aucun commentaire:
Enregistrer un commentaire