generic_asynctask_v2
generic_asynctask_v2 copied to clipboard
Can't load image.
package com.example.umer9.lbfvf1.user;
import android.content.Intent; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.AdapterView; import android.widget.ImageView; import android.widget.ListView; import android.widget.Toast;
import com.amigold.fundapter.BindDictionary; import com.amigold.fundapter.FunDapter; import com.amigold.fundapter.extractors.StringExtractor; import com.amigold.fundapter.interfaces.DynamicImageLoader; import com.example.umer9.lbfvf1.R; import com.kosalgeek.android.json.JsonConverter; import com.kosalgeek.genasync12.AsyncResponse; import com.kosalgeek.genasync12.PostResponseAsyncTask; import com.squareup.picasso.Picasso;
import java.io.Serializable; import java.util.ArrayList;
public class ListActivity extends AppCompatActivity implements AsyncResponse, AdapterView.OnItemClickListener{
final String LOG = "ListActivity";
private ArrayList<Post> bookList;
private ListView lvBook;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list);
Bundle searchThis= getIntent().getExtras();
String myParam = searchThis.getString("searchThis");
PostResponseAsyncTask taskRead = new PostResponseAsyncTask(ListActivity.this, this);
taskRead.execute("http://10.0.0.102/lbf_fyp/api/search.php?string="+myParam);
}
@Override
public void processFinish(String s) {
if (s == null || s.isEmpty()) {
Intent intent = new Intent(ListActivity.this, User_Main.class);
Toast.makeText(ListActivity.this, "No Record Found", Toast.LENGTH_LONG).show();
startActivity(intent);
}
else {
ArrayList<Post> bookList = new JsonConverter<Post>().toArrayList(s, Post.class);
BindDictionary<Post> dict = new BindDictionary<Post>();
dict.addStringField(R.id.title, new StringExtractor<Post>() {
@Override
public String getStringValue(Post item, int position) {
return item.b_title;
}
});
dict.addStringField(R.id.author, new StringExtractor<Post>() {
@Override
public String getStringValue(Post item, int position) {
return item.b_author;
}
});
dict.addStringField(R.id.isbn, new StringExtractor<Post>() {
@Override
public String getStringValue(Post item, int position) {
return item.b_isbn;
}
});
dict.addStringField(R.id.avail_on, new StringExtractor<Post>() {
@Override
public String getStringValue(Post item, int position) {
return ""+item.last_availbleDate;
}
});
dict.addStringField(R.id.rownum, new StringExtractor<Post>() {
@Override
public String getStringValue(Post item, int position) {
return "" + item.b_row;
}
});
dict.addStringField(R.id.standnum, new StringExtractor<Post>() {
@Override
public String getStringValue(Post item, int position) {
return "" + item.b_stand;
}
});
dict.addStringField(R.id.shelvenum, new StringExtractor<Post>() {
@Override
public String getStringValue(Post item, int position) {
return "" + item.b_shelf;
}
});
dict.addDynamicImageField(R.id.b_img, new StringExtractor<Post>() {
@Override
public String getStringValue(Post item, int position) {
return item.b_img;
}
}, new DynamicImageLoader() {
@Override
public void loadImage(String url, ImageView view) {
Picasso.with(ListActivity.this).load(url).into(view);
}
});
FunDapter<Post> adapter = new FunDapter<>(ListActivity.this,
bookList, R.layout.books_list, dict);
lvBook = (ListView) findViewById(R.id.lvBook);
lvBook.setAdapter(adapter);
}
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Post selectedBook = bookList.get(position);
Intent intent = new Intent(ListActivity.this, DetaileActivity.class);
intent.putExtra("book", (Serializable) selectedBook);
startActivity(intent);
}
} //Serialized data public class Post {
@SerializedName("b_title")
public String b_title;
@SerializedName("b_author")
public String b_author;
@SerializedName("b_isbn")
public String b_isbn;
@SerializedName("last_availbleDate")
public String last_availbleDate;
@SerializedName("b_row")
public int b_row;
@SerializedName("b_stand")
public int b_stand;
@SerializedName("b_shelf")
public int b_shelf;
@SerializedName("b_img")
public String b_img;
}
//In you given video part 1, I tried to put an image in listView. Here's my XML
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent">
<RelativeLayout
android:id="@+id/left"
android:layout_weight="1"
android:layout_margin="6dp"
android:layout_width="match_parent"
android:layout_height="170dp"
android:background="@color/itembg">
<RelativeLayout
android:id="@+id/tv"
android:layout_width="215dp"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/headings"
android:layout_alignBottom="@+id/headings"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_margin="6dp"
android:layout_toEndOf="@+id/headings"
android:layout_toRightOf="@+id/headings">
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Body1"
android:textSize="15dp" />
<TextView
android:id="@+id/author"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/title"
android:layout_alignStart="@+id/title"
android:layout_below="@+id/title"
android:textSize="15dp" />
<TextView
android:id="@+id/isbn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/author"
android:layout_alignStart="@+id/author"
android:layout_below="@+id/author"
android:width="@dimen/activity_vertical_margin"
android:textSize="15dp" />
<TextView
android:id="@+id/avail_on"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/isbn"
android:layout_alignStart="@+id/isbn"
android:layout_below="@+id/isbn"
android:width="@dimen/activity_vertical_margin"
android:textSize="15dp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="150dp"
android:layout_height="100dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="false">
<ImageView
android:id="@+id/b_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/rss_headings"
android:layout_below="@+id/tv"
android:layout_marginTop="8dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:weightSum="3">
<TextView
android:id="@+id/row"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="20dp"
android:layout_marginStart="20dp"
android:text="Row"
android:textSize="15dp" />
<TextView
android:id="@+id/stand"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Stand"
android:textSize="15dp" />
<TextView
android:id="@+id/shelve"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginEnd="20dp"
android:layout_marginRight="20dp"
android:text="Shelve"
android:textSize="15dp" />
</LinearLayout>
</RelativeLayout>
<LinearLayout
android:layout_below="@+id/rss_headings"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="3">
<TextView
android:id="@+id/rownum"
android:layout_weight="1"
android:textSize="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginStart="30dp"/>
<TextView
android:id="@+id/standnum"
android:layout_weight="1"
android:textSize="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/shelvenum"
android:layout_weight="1"
android:layout_marginEnd="35dp"
android:layout_marginRight="35dp"
android:textSize="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</RelativeLayout>