ListView klikledikde diger sayfaya foto gonderme
Merhabalar, sorum su. Ana sayfada Listview var ve listview'nu kilikliyende diger sayfada listviewdaki verileri gostermeli.TextView diger sayfada geldi ama ImagaView getiremedim. yardimci olun lutfen
MainActivity.java
[code]
public class MainActivity extends Activity {
static String TITLE = "title";
static String TITLE_SONLUQ = "title_sonluq";
static String TITLE_TEFERRUAT = "detail";
static String TITLE_IMAGE = "image";
ArrayList<Actors> actorsList;
ActorAdapter adapter;
DownloadImageTask downloadImagetask;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
actorsList = new ArrayList<Actors>();
new JSONAsyncTask().execute("http://qafqazinfo.az/api3.php");
ListView listview = (ListView)findViewById(R.id.list);
adapter = new ActorAdapter(getApplicationContext(), R.layout.row, actorsList);
listview.setAdapter(adapter);
listview.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View view, int position, long id) {
String title = ((TextView) view.findViewById(R.id.titleBasliq)).getText().toString();
String title_sonluq = ((TextView) view.findViewById(R.id.titleSonluq)).getText().toString();
String detail = ((TextView) view.findViewById(R.id.detail)).getText().toString();
Intent intent = new Intent(MainActivity.this, SingleItemView.class);
intent.putExtra(TITLE, title);
intent.putExtra(TITLE_SONLUQ, title_sonluq);
intent.putExtra(TITLE_TEFERRUAT, detail);
startActivity(intent);
}
});
}
class JSONAsyncTask extends AsyncTask<String, Void, Boolean> {
ProgressDialog dialog;
@Override
protected void onPreExecute() {
super.onPreExecute();
dialog = new ProgressDialog(MainActivity.this);
dialog.setMessage("Loading, please wait");
dialog.setTitle("Connecting server");
dialog.show();
dialog.setCancelable(false);
}
@Override
protected Boolean doInBackground(String... urls) {
try {
//------------------>>
HttpGet httppost = new HttpGet(urls[0]);
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = httpclient.execute(httppost);
// StatusLine stat = response.getStatusLine();
int status = response.getStatusLine().getStatusCode();
if (status == 200) {
HttpEntity entity = response.getEntity();
String data = EntityUtils.toString(entity);
JSONObject jsono = new JSONObject(data);
JSONArray jarray = jsono.getJSONArray("xeberler");
for (int i = 0; i < jarray.length(); i++) {
JSONObject object = jarray.getJSONObject(i);
Actors actor = new Actors();
actor.setTitle(object.getString("title"));
actor.setTitle_sonluq(object.getString("title_sonluq"));
actor.setDetail(object.getString("detail"));
actor.setImage(object.getString("image"));
actorsList.add(actor);
}
return true;
}
//------------------>>
} catch (ParseException e1) {
e1.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
return false;
}
protected void onPostExecute(Boolean result) {
dialog.cancel();
adapter.notifyDataSetChanged();
if(result == false)
Toast.makeText(getApplicationContext(), "Unable to fetch data from server", Toast.LENGTH_LONG).show();
}
}
}
[/code]
ActorAdapter.java
[code]
public class ActorAdapter extends ArrayAdapter<Actors> {
ArrayList<Actors> actorList;
Context context;
LayoutInflater vi;
int Resource;
ViewHolder holder;
public ActorAdapter(Context context, int resource, ArrayList<Actors> objects) {
super(context, resource, objects);
vi = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
Resource = resource;
actorList = objects;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
// convert view = design
View v = convertView;
if (v == null) {
holder = new ViewHolder();
v = vi.inflate(Resource, null);
holder.imageview = (ImageView) v.findViewById(R.id.imagev);
holder.tvTitle = (TextView) v.findViewById(R.id.titleBasliq);
holder.tvTitle_sonluq = (TextView) v.findViewById(R.id.titleSonluq);
holder.tvDetail = (TextView) v.findViewById(R.id.detail);
v.setTag(holder);
} else {
holder = (ViewHolder) v.getTag();
}
holder.imageview.setImageResource(R.drawable.ic_launcher);
new DownloadImageTask(holder.imageview).execute(actorList.get(position).getImage());
holder.tvTitle.setText(actorList.get(position).getTitle());
holder.tvTitle_sonluq.setText(actorList.get(position).getTitle_sonluq());
holder.tvDetail.setText(actorList.get(position).getDetail());
holder.tvDetail.setVisibility(View.GONE);
return v;
}
static class ViewHolder {
public ImageView imageview;
public TextView tvTitle;
public TextView tvTitle_sonluq;
public TextView tvDetail;
}
class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
ImageView bmImage;
public DownloadImageTask(ImageView bmImage) {
this.bmImage = bmImage;
}
protected Bitmap doInBackground(String... urls) {
String urldisplay = urls[0];
Bitmap mIcon11 = null;
try {
InputStream in = new java.net.URL(urldisplay).openStream();
mIcon11 = BitmapFactory.decodeStream(in);
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return mIcon11;
}
protected void onPostExecute(Bitmap result) {
bmImage.setImageBitmap(result);
}
}
}
[/code]
SingleItemView.java
[code]protected void onCreate(Bundle savedInstanceState) {
final String TAG_XEBER_BASLIQ = "title";
final String TAG_XEBER_SONLUQ = "title_sonluq";
final String TAG_DETAIL = "detail";
final String TAG_IMAGE = "image";
TextView basliq_xeber;
TextView sonluq_xeber;
TextView teferruat_xeber;
ImageView sekil_xeber;
super.onCreate(savedInstanceState);
setContentView(R.layout.singleitemview);
Intent i = getIntent();
String basliq = i.getStringExtra(TAG_XEBER_BASLIQ);
String sonluq = i.getStringExtra(TAG_XEBER_SONLUQ);
String teferruat = i.getStringExtra(TAG_DETAIL);
String sekil = i.getStringExtra(TAG_IMAGE);
basliq_xeber = (TextView) findViewById(R.id.xeber_basliq);
sonluq_xeber = (TextView) findViewById(R.id.xeber_sonluq);
teferruat_xeber = (TextView) findViewById(R.id.xeber_tefferuat);
basliq_xeber.setText(basliq);
sonluq_xeber.setText(sonluq);
teferruat_xeber.setText(teferruat);
}
}[/code]
singleitemview.xml
[code]
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/xeber_basliq"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Xeber Basligi"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="-"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/xeber_sonluq"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Xeber Sonlugu"
android:textColor="#F30A1A"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
<ImageView
android:id="@+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="150dp"
android:src="@drawable/ic_launcher" />
<TextView
android:id="@+id/xeber_tefferuat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Xeberin teferrurti"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</ScrollView>
</LinearLayout>
[/code]
row.xml
[code]
<?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="horizontal" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="115dp"
android:orientation="horizontal" >
<ImageView
android:id="@+id/imagev"
android:layout_width="105dp"
android:layout_height="match_parent"
android:src="@drawable/ic_launcher" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/titleBasliq"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#166CED"
android:text="sdfgh" />
<TextView
android:id="@+id/titleSonluq"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15dp"
android:textColor="#F9065F"
android:textStyle="bold"
android:text="sdfgh"/>
<TextView
android:id="@+id/detail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="sdfghsdfgyuytrhgfdser5tgfdsfrtyhujyhgfdfgbhyuj" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
[/code]