android basic image gallery code error? - android

i am developing the main activity at the moment that displays multiple images vertically that can be scrolled down. later i would use each image as a thumbnail to a video.
but imageview displays one image only
can someone guide me through it.
Resources res = getResources(); //if you are in an activity
AssetManager am = res.getAssets();
//String temp="";
String fileList[];
try {
fileList = am.list("thumbs");
if (fileList != null)
{
for ( int i = 0;i<fileList.length;i++)
{
Log.d("",fileList[i]);
//temp = temp + fileList[i] + ", ";
if (i == 0)
{
mImage = (ImageView)findViewById(R.id.imageView1);
Drawable d = fetchThumb(fileList[0]);
mImage.setImageDrawable(d);
}
else if(i == 1)
{
mImage = (ImageView)findViewById(R.id.imageView2);
Drawable d = fetchThumb(fileList[1]);
mImage.setImageDrawable(d);
}
else if(i == 2)
{
mImage = (ImageView)findViewById(R.id.imageView3);
Drawable d = fetchThumb(fileList[2]);
mImage.setImageDrawable(d);
}
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public Drawable fetchThumb(String filename)
{
try
{
InputStream ims = getAssets().open(filename);
Drawable d = Drawable.createFromStream(ims, null);
return d;
}
catch(IOException ex)
{return null;}
}
xml file to display images:
<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:isScrollContainer="true"
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" >
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<ImageView
android:id="#+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
</RelativeLayout>

Related

Couldn't Expand RemoteViews - Using Compatible Views, Still Error

I've checked the following question, As seen i understood that i can only use compatible views with RemoteViews, i'm using a Linear and ImageView which are working, every time i trigger the Notification method, i get the " Couldn't expand Remoteviews " error .
My layout is as the following :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:padding="5dp">
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/AppIcon1" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/AppIcon2" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/AppIcon3" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/AppIcon4" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/AppIcon5" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/AppIcon6" />
</LinearLayout>
</LinearLayout>
Sending Notify Code :
private void SendNotifyShortcuts(){
UpdatePreferences();
nBuilder = new NotificationCompat.Builder(this)
.setAutoCancel(true)
.setOngoing(true);
remoteView = new RemoteViews(getPackageName(), R.layout.notification_layout);
if (App_1 == null) {
remoteView.setImageViewResource(R.id.AppIcon1, R.drawable.app_fab);
} else {
Drawable icon = null;
Bitmap AppIcon = null;
final PackageManager pm = getApplicationContext().getPackageManager();
try {
ApplicationInfo ai = pm.getApplicationInfo(App_1, 0);
icon = getPackageManager().getApplicationIcon(App_1);
AppIcon = ((BitmapDrawable) icon).getBitmap();
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
remoteView.setImageViewBitmap(R.id.AppIcon1, AppIcon);
}
if (App_2 == null) {
remoteView.setImageViewResource(R.id.AppIcon2, R.drawable.app_fab);
} else {
Drawable icon = null;
Bitmap AppIcon = null;
final PackageManager pm = getApplicationContext().getPackageManager();
try {
ApplicationInfo ai = pm.getApplicationInfo(App_2, 0);
icon = getPackageManager().getApplicationIcon(App_2);
AppIcon = ((BitmapDrawable) icon).getBitmap();
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
remoteView.setImageViewBitmap(R.id.AppIcon2, AppIcon);
}
if (App_3 == null) {
remoteView.setImageViewResource(R.id.AppIcon3, R.drawable.app_fab);
} else {
Drawable icon = null;
Bitmap AppIcon = null;
final PackageManager pm = getApplicationContext().getPackageManager();
try {
ApplicationInfo ai = pm.getApplicationInfo(App_3, 0);
icon = getPackageManager().getApplicationIcon(App_3);
AppIcon = ((BitmapDrawable) icon).getBitmap();
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
remoteView.setImageViewBitmap(R.id.AppIcon3, AppIcon);
}
if (App_4 == null) {
remoteView.setImageViewResource(R.id.AppIcon4, R.drawable.app_fab);
} else {
Drawable icon = null;
Bitmap AppIcon = null;
final PackageManager pm = getApplicationContext().getPackageManager();
try {
ApplicationInfo ai = pm.getApplicationInfo(App_4, 0);
icon = getPackageManager().getApplicationIcon(App_4);
AppIcon = ((BitmapDrawable) icon).getBitmap();
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
remoteView.setImageViewBitmap(R.id.AppIcon4, AppIcon);
}
if (App_5 == null) {
remoteView.setImageViewResource(R.id.AppIcon5, R.drawable.app_fab);
} else {
Drawable icon = null;
Bitmap AppIcon = null;
final PackageManager pm = getApplicationContext().getPackageManager();
try {
ApplicationInfo ai = pm.getApplicationInfo(App_5, 0);
icon = getPackageManager().getApplicationIcon(App_5);
AppIcon = ((BitmapDrawable) icon).getBitmap();
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
remoteView.setImageViewBitmap(R.id.AppIcon5, AppIcon);
}
if (App_6 == null) {
remoteView.setImageViewResource(R.id.AppIcon6, R.drawable.app_fab);
} else {
Drawable icon = null;
Bitmap AppIcon = null;
final PackageManager pm = getApplicationContext().getPackageManager();
try {
ApplicationInfo ai = pm.getApplicationInfo(App_6, 0);
icon = getPackageManager().getApplicationIcon(App_6);
AppIcon = ((BitmapDrawable) icon).getBitmap();
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
remoteView.setImageViewBitmap(R.id.AppIcon6, AppIcon);
}
setListeners(remoteView, this);
nBuilder.setContent(remoteView);
nManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
nManager.notify(NOFIY_ID, nBuilder.build());
}
public static void CancelNotify(){
try {
nManager.cancel(NOFIY_ID);
} catch (Exception e){
e.printStackTrace();
}
}
public static void setListeners(RemoteViews view, Context context){
Intent App1 = new Intent("App1");
PendingIntent App1P = PendingIntent.getBroadcast(context, 0, App1, 0);
view.setOnClickPendingIntent(R.id.AppIcon1, App1P);
Intent App2 = new Intent("App2");
PendingIntent App2P = PendingIntent.getBroadcast(context, 1, App2, 0);
view.setOnClickPendingIntent(R.id.AppIcon2, App2P);
Intent App3 = new Intent("App3");
PendingIntent App3P = PendingIntent.getBroadcast(context, 3, App3, 0);
view.setOnClickPendingIntent(R.id.AppIcon2, App3P);
Intent App4 = new Intent("App4");
PendingIntent App4P = PendingIntent.getBroadcast(context, 4, App4, 0);
view.setOnClickPendingIntent(R.id.AppIcon2, App4P);
Intent App5 = new Intent("App5");
PendingIntent App5P = PendingIntent.getBroadcast(context, 5, App5, 0);
view.setOnClickPendingIntent(R.id.AppIcon2, App5P);
Intent App6 = new Intent("App6");
PendingIntent App6P = PendingIntent.getBroadcast(context, 6, App6, 0);
view.setOnClickPendingIntent(R.id.AppIcon2, App6P);
}
What's the fix ? And i've seen in the questions that i can make a ListView in a notification, What's the way ? as there is no official doc or guide to do it .

Display full screen image in ImageView

I want to display full screen image on another activity after clicking an imageview. I have 6 ImageViews in my layout and each ImageView is getting image from Parse backend. How can I display image on fetching the imagepath ?
public ImageLoader imgl;
ImageView ad1,ad2,ad3,ad4,ad5,ad6;
List<ParseObject> ob;
private ImageView[] imgs = new ImageView[5];
int k=0;
ad1=(ImageView) findViewById(R.id.ad1);
ad2=(ImageView) findViewById(R.id.ad2);
ad3=(ImageView) findViewById(R.id.ad3);
ad4=(ImageView) findViewById(R.id.ad4);
ad5=(ImageView) findViewById(R.id.ad5);
ad6=(ImageView) findViewById(R.id.ad6);
imgs[0] = ad2;
imgs[1] = ad3;
imgs[2] = ad4;
imgs[3] = ad5;
imgs[4] = ad6;
ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("Adverts");
query.orderByDescending("updatedAt");
query.whereEqualTo("Status", true);
try {
ob = query.find();
System.out.println("the urls areeee "+ob);
for (ParseObject country : ob) {
ParseFile image = (ParseFile) country.get("imageFile");
imgl.DisplayImage(image.getUrl(), imgs[k]);
k=k+1;
System.out.println("the urls are"+image.getUrl());
pd.dismiss();
}
} catch (com.parse.ParseException e) {
// TODO Auto-generated catch block
pd.dismiss();
e.printStackTrace();
}
ad1.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent ent= new Intent(HomeActivity.this,AdvertsActivity.class);
startActivity(ent);
}
});
}
Set click listener on your ImageView and pass your image url in argument and call method
private void viewImage(String url)
{
final Dialog nagDialog = new Dialog(ProjectDetailActivity.this,android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
nagDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
nagDialog.setCancelable(false);
nagDialog.setContentView(R.layout.dialog_full_image);
ivPreview = (ImageView)nagDialog.findViewById(R.id.imageView1);
BitmapDrawable bmd = (BitmapDrawable)getDrawableFromUrl(url)
Bitmap bitmap = bmd.getBitmap();
ivPreview.setImageBitmap(bitmap);
nagDialog.show();
}
public Drawable getDrawableFromUrl(String imgUrl)
{
if(imgUrl == null || imgUrl.equals(""))
return null;
try
{
URL url = new URL(imgUrl);
InputStream in = url.openStream();
Drawable d = Drawable.createFromStream(in, imgUrl);
return d;
}
catch (Exception e)
{
e.printStackTrace();
}
return null;
}
use xml file
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#android:color/white"
android:layout_gravity="center" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:contentDescription="#string/hello_world"
android:src="#android:color/white"
android:layout_margin="5dp"
android:scaleType="centerInside"/>
</RelativeLayout>

Inserting image from assets folder into a ListView

ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
JSONObject json = jParser.getJSONFromUrl("http://domain.com/directory/database/retrieveComments.php?placeId=" + stringPlaceId);
try
{
commentsRatingsArray = json.getJSONArray("commentsRatings");
for(int i = 0; i < commentsRatingsArray.length(); i++)
{
JSONObject jsonObject = commentsRatingsArray.getJSONObject(i);
String dbUserFullName = jsonObject.getString(TAG_FULLNAME);
String dbUserEmail = jsonObject.getString(TAG_EMAIL);
String dbComment = jsonObject.getString(TAG_COMMENT);
String dbRating = jsonObject.getString(TAG_RATING);
String dbDate = jsonObject.getString(TAG_DATE);
String dbTime = jsonObject.getString(TAG_TIME);
HashMap<String, String> map = new HashMap<String, String>();
map.put(TAG_FULLNAME, dbUserFullName);
map.put(TAG_EMAIL, dbUserEmail);
map.put(TAG_COMMENT, dbComment);
map.put(TAG_RATING, dbRating);
map.put(TAG_DATE, dbDate);
map.put(TAG_TIME, dbTime);
list.add(map);
}
}
catch (Exception e)
{
e.printStackTrace();
Toast.makeText(getBaseContext(), "Connection to the server is lost. Please check your internet connection.", Toast.LENGTH_SHORT).show();
}
ListAdapter adapter = new SimpleAdapter
(DisplayCommentsRatings.this, list, R.layout.commentrating,
new String[] { TAG_FULLNAME, TAG_EMAIL, TAG_COMMENT, TAG_DATE, TAG_TIME },
new int[] {R.id.tvUserFullName, R.id.tvUserEmail, R.id.tvUserComment, R.id.tvDate, R.id.tvTime });
setListAdapter(adapter);
Here's my code, I'm getting these JSON Array values from my database. I just want to know how to change an image's src inside a list view. Because I will only use 5 images, I decided to include these images in my assets folder instead of uploading them to the web.
Can someone give me an idea to make this possible?
Here's my XML code:
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/tvUserFullName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
android:textSize="12dip"
android:textStyle="bold"/>
//This is the imageView where I will display the image from the assets folder
<ImageView
android:id="#+id/ivUserRating"
android:layout_width="100dip"
android:layout_height="fill_parent"
android:src="#drawable/zerostar"/>
</LinearLayout>
<TextView
android:id="#+id/tvUserEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="EmailAddress#domain.com"
android:textSize="9dip"/>
<TextView
android:id="#+id/tvUserComment"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text='"This is a comment. This is a comment. This is a comment. This is a comment. This is a comment."'
android:textSize="10dip"
android:layout_margin="3dip"
android:textColor="#000000"
android:maxLength="300"/>
<TextView
android:id="#+id/tvDate"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="August 1, 2010"
android:textColor="#000000"
android:textSize="8dip"
android:layout_gravity="right"/>
<TextView
android:id="#+id/tvTime"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="08:20 PM"
android:textColor="#000000"
android:textSize="8dip"
android:layout_gravity="right"/>
Use SimpleAdapter as normal, but be sure to override you "adapter"'s the setViewBinder method like:
adapter.setViewBinder(new ViewBinder() {
public boolean setViewValue(View view, Object data,
String textRepresentation) {
// Check wether it's ImageView and the data
if(view instanceof ImageView && data instanceof Bitmap){
ImageView iv = (ImageView) view;
iv.setImageBitmap((Bitmap) data);
return true;
}else
return false;
}
});
then use a getBitmap() to get the assert image
public Bitmap getBitmap( String path, int i ){
Bitmap mBitmap = null;
try {
AssetManager assetManager = getAssets();
String[] files = null;
files = assetManager.list( "smartmodel/" + path );
Log.i( "Assert List", files[1].toString() );
// Pass ur file path, here is one in assert/smartmodel/ filer
mBitmap = BitmapFactory.decodeStream( this.getAssets().open( "smartmodel/" + path + "/"+ files[i]) );
} catch (Exception e) {
e.printStackTrace();
}
return mBitmap;
}
Last, in your Simple adapter List parameter, put
map.put( "ItemImage", getBitmap( gridItemName, i ));
Your passed getBitmap(...) will be show.
check position and use like,
Bitmap bmp=null;
if(position==0){
bitmap=getBitmap("img0.png");
}else if (position==1){
bitmap=getBitmap("img1.png");
}
.
.
.
Method::
private Bitmap getBitmap(String name) throws IOException
{
AssetManager asset = getAssets();
InputStream is = asset.open(name);
Bitmap bitmap = BitmapFactory.decodeStream(is);
return bitmap;
}

Scrolling is not perform in Listview in android

I have a problem that, I am adding listview in LinearLayout dynamically through code and set the EndlessAdapter into that, Data is shown correctly but we are unable to scroll from top to bottom in the list. I don't know why? please suggest me any solution regarding the same.
Code:
public void setValuesInCategoryChild(String url, final String filter, final String from, final String to) {
if (isOnline()) {
final ProgressDialog dialog = ProgressDialog.show(ResearchList.this, "Research List ", "Please wait... ", true);
final Handler handler = new Handler() {
public void handleMessage(Message msg) {
// System.out.println("The id after Save:"+id.get(0).toString());
// catagory.addAll(keyword_vector1);
linear_Category_Child.setVisibility(View.GONE);
linear_Category_Child_Child.setVisibility(View.VISIBLE);
// tv_Child_Header.setText("Volvo");
tv_CategoryChildHeader.setText(from);
setHeaderImage(tv_CategoryChildHeader.getText().toString());
System.out.println("The size of Cat Display names:" + coll.getDisplayNames().size());
System.out.println("The size of Cat Images:" + coll.getImages().size());
System.out.println("The size of Cat price:" + coll.getPrice().size());
System.out.println("The size of Cat Year:" + coll.getYears().size());
System.out.println("The size of Cat Rating:" + coll.getRating().size());
System.out.println("The size of Cat Mpg:" + coll.getMpg().size());
setHeaderImage(tv_CategoryChildHeader.getText().toString());
if(coll.getDisplayNames().size()!=0) {
lvCategory = new ListView(ResearchList.this);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
lvCategory.setLayoutParams(params);
// Adapter for MPG Search
demoAdapterCat = new DemoAdapterCat();
lvCategory.setAdapter(demoAdapterCat);
layout_ResearchList_BrandList.addView(lvCategory);
Utility.setListViewHeightBasedOnChildren(lvCategory);
}else {
/*lvCategory.invalidate();
lvCategory.setAdapter(null);*/
AlertDialog.Builder builder = new Builder(ResearchList.this);
builder.setTitle("Attention!");
builder.setMessage("No Data Available for the Particular Search.");
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
});
builder.create().show();
}
/*Utility util = new Utility();
util.setListViewHeightBasedOnChildren(lvCategory);*/
dialog.dismiss();
}
};
final Thread checkUpdate = new Thread() {
public void run() {
try {
String sortEncode = URLEncoder.encode("mpg");
String filterEncode = URLEncoder.encode(filter);
String clientEncode = URLEncoder.encode("10030812");
String fromEncode = URLEncoder.encode(from);
String toEncode = URLEncoder.encode(to);
String catUrl = "/v1/vehicles/get-make-models.json?sort=" + sortEncode + "&filter=" + filterEncode + "&client-id=" + clientEncode + "&from=" + fromEncode;
genSig = new GetSignature(catUrl, "acura");
try {
signature = genSig.getUrlFromString();
} catch (InvalidKeyException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (NoSuchAlgorithmException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
// jsonString =
// getJsonSring("http://api.highgearmedia.com/v1/vehicles/get-models.json?make=acura&client-id=10030812&signature=LWQbdAlJVxlXZ1VO2mfqAA==");
// String signatureEncode =
// URLEncoder.encode(signature);
String urlEncode = URLEncoder.encode(catUrl + "&signature=" + signature);
jsonString = getJsonSring("http://apibeta.highgearmedia.com" + catUrl + "&signature=" + signature);
System.out.println("The json category:===>" + jsonString);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
JsonParse json = new JsonParse(jsonString);
json.parseCat();
LIST_SIZE = coll.getDisplayNames().size();
for (int i = 0; i <= BATCH_SIZE; i++) {
// countriesSub.add(COUNTRIES[i]);
countriesSubCat.add(coll.getDisplayNames().get(i));
imagesSubCat.add(coll.getImages().get(i));
YearSubCat1.add(coll.getYears().get(i));
YearSubCat2.add(coll.getYears().get(i + 1));
mpgSubCat1.add(coll.getMpg().get(i));
mpgSubCat2.add(coll.getMpg().get(i + 1));
priceSubCat1.add(coll.getPrice().get(i));
priceSubCat2.add(coll.getPrice().get(i + 1));
ratingSubCat1.add(coll.getRating().get(i));
ratingSubCat2.add(coll.getRating().get(i + 1));
}
setLastOffset(BATCH_SIZE);
handler.sendEmptyMessage(0);
}
};
checkUpdate.start();
} else {
AlertDialog.Builder builder = new Builder(ResearchList.this);
builder.setTitle("Attention!");
builder.setMessage("Network Connection unavailable.");
builder.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
});
builder.create().show();
}
}
Layout:
<LinearLayout
android:id="#+id/linear_ResearchListCategoryChild_Child"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="gone" >
<RelativeLayout
android:id="#+id/linear_ResearchListCategoryChild_Child_HeaderBlock"
android:layout_width="fill_parent"
android:layout_height="40dip"
android:background="#drawable/catagory_bar"
android:orientation="horizontal" >
<TextView
android:id="#+id/tv_ResearchListCategoryChild_Child_Header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="Work in Progress"
android:textColor="#ffffff"
android:textStyle="bold" android:layout_marginLeft="60dip"/>
<ImageView
android:id="#+id/img_ResearchListCategory_ChildHeader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="10dip"
android:src="#drawable/up_arrow" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:src="#drawable/list_arrow_up" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/linear_ResearchListCategoryChild_Child_Header"
android:layout_width="fill_parent"
android:layout_height="40dip"
android:background="#drawable/nav_bg"
android:orientation="horizontal" >
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="5dip"
android:clickable="true"
android:text="Highest Rated"
android:textColor="#ffffff"
android:textStyle="bold" android:gravity="center"/>
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView5"
android:layout_alignBottom="#+id/textView5"
android:layout_marginLeft="30dp"
android:layout_toRightOf="#+id/textView5"
android:clickable="true"
android:text="A-Z"
android:textColor="#ffffff"
android:textStyle="bold" android:gravity="center"/>
<TextView
android:id="#+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView6"
android:layout_alignBottom="#+id/textView6"
android:layout_marginLeft="40dp"
android:layout_toRightOf="#+id/textView6"
android:clickable="true"
android:text="Price"
android:textColor="#ffffff"
android:textStyle="bold" android:gravity="center"/>
<TextView
android:id="#+id/textView8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView7"
android:layout_alignBottom="#+id/textView7"
android:layout_alignParentRight="true"
android:layout_marginRight="14dp"
android:clickable="true"
android:text="MPG"
android:textColor="#ffffff"
android:textStyle="bold" android:gravity="center"/>
</RelativeLayout>
<!--
<RelativeLayout
android:id="#+id/relative_down_arrow"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="visible"
>
</RelativeLayout>
-->
<LinearLayout
android:id="#+id/linearArrowLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:visibility="visible">
<ImageView
android:id="#+id/Highly_rated"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="51dp"
android:src="#drawable/selector_arrow"
android:visibility="invisible" />
<ImageView
android:id="#+id/AZ_arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="78dp"
android:src="#drawable/selector_arrow"
android:visibility="invisible" />
<ImageView
android:id="#+id/Price_arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="59dp"
android:src="#drawable/selector_arrow"
android:visibility="invisible" />
<ImageView
android:id="#+id/MPG"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="55dp"
android:src="#drawable/selector_arrow"
android:visibility="invisible" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="12dip"
android:layout_marginRight="12dip" android:background="#ffffff" android:id="#+id/layout_ResearchList_BrandList">
</LinearLayout>
</LinearLayout>
DemoAdapterCat:
class DemoAdapterCat extends EndlessAdapter {
ImageLoader image = new ImageLoader(ResearchList.this);
private RotateAnimation rotate = null;
ArrayList<String> tempListNamesCat = new ArrayList<String>();
ArrayList<String> tempListImagesCat = new ArrayList<String>();
ArrayList<String> tempListYearCat1 = new ArrayList<String>();
ArrayList<String> tempListYearCat2 = new ArrayList<String>();
ArrayList<String> tempListmpgCat1 = new ArrayList<String>();
ArrayList<String> tempListmpgCat2 = new ArrayList<String>();
ArrayList<String> tempListpriceCat1 = new ArrayList<String>();
ArrayList<String> tempListpriceCat2 = new ArrayList<String>();
ArrayList<String> tempListRatingCat1 = new ArrayList<String>();
ArrayList<String> tempListRatingCat2 = new ArrayList<String>();
DemoAdapterCat() {
super(new CategoryListLazyAdapter(ResearchList.this,
countriesSubCat, imagesSubCat, YearSubCat1, YearSubCat2,
mpgSubCat1, mpgSubCat2, priceSubCat1, priceSubCat2,
ratingSubCat1, ratingSubCat2));
/*Utility util = new Utility();
util.setListViewHeightBasedOnChildren(lvCategory);*/
rotate = new RotateAnimation(0f, 360f, Animation.RELATIVE_TO_SELF,
0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rotate.setDuration(600);
rotate.setRepeatMode(Animation.RESTART);
rotate.setRepeatCount(Animation.INFINITE);
}
/*
* #Override public int getCount() { return
* brandList.getDisplayNames().size(); //return count+=10; }
*/
#Override
protected View getPendingView(ViewGroup parent) {
row = getLayoutInflater().inflate(R.layout.categorylist, null);
child = row.findViewById(R.id.tv_CategoryItem_Name);
child.setVisibility(View.GONE);
child = row.findViewById(R.id.tv_CategoryItem_MPG1);
child.setVisibility(View.GONE);
child = row.findViewById(R.id.tv_CategoryItem_MPG2);
child.setVisibility(View.GONE);
child = row.findViewById(R.id.tv_CategoryItem_Price1);
child.setVisibility(View.GONE);
child = row.findViewById(R.id.tv_CategoryItem_Price2);
child.setVisibility(View.GONE);
child = row.findViewById(R.id.tv_CategoryItem_Rating1);
child.setVisibility(View.GONE);
child = row.findViewById(R.id.tv_CategoryItem_Rating2);
child.setVisibility(View.GONE);
child = row.findViewById(R.id.tv_CategoryItem_Year1);
child.setVisibility(View.GONE);
child = row.findViewById(R.id.tv_CategoryItem_Year2);
child.setVisibility(View.GONE);
child = row.findViewById(R.id.linear_CategoryList_itemlayer1);
child.setVisibility(View.GONE);
child = row.findViewById(R.id.linear_CategoryList_itemlayer2);
child.setVisibility(View.GONE);
/*
* child = row.findViewById(R.id.img_CategoryItem);
* child.setVisibility(View.GONE); child =
* row.findViewById(R.id.img_CategoryItem_Arrow);
* child.setVisibility(View.GONE);
*/
/*
* child = row.findViewById(R.id.linear_main_MPG);
* child.setVisibility(View.GONE);
*/
child = row.findViewById(R.id.throbber);
child.setVisibility(View.VISIBLE);
child.startAnimation(rotate);
return (row);
}
#Override
protected boolean cacheInBackground() {
//count += 10;
SystemClock.sleep(100000);
tempListNamesCat.clear();
tempListImagesCat.clear();
tempListmpgCat1.clear();
tempListmpgCat2.clear();
tempListpriceCat1.clear();
tempListpriceCat2.clear();
tempListYearCat1.clear();
tempListYearCat2.clear();
tempListRatingCat1.clear();
tempListRatingCat2.clear();
// countriesSubCat.clear();
// imagesSubCat.clear();
// YearSubCat1.clear();
// YearSubCat2.clear();
// mpgSubCat1.clear();
// mpgSubCat2.clear();
// priceSubCat1.clear();
// priceSubCat2.clear();
// ratingSubCat1.clear();
// ratingSubCat2.clear();
int lastOffset = getLastOffset();
if (lastOffset < LIST_SIZE) {
int limit = lastOffset + BATCH_SIZE;
for (int i = (lastOffset + 1); (i <= limit && i < LIST_SIZE); i++) {
tempListNamesCat.add(coll.getDisplayNames().get(i));
tempListImagesCat.add(coll.getImages().get(i));
tempListmpgCat1.add(coll.getMpg().get(i));
tempListmpgCat2.add(coll.getMpg().get(i + 1));
tempListpriceCat1.add(coll.getPrice().get(i));
tempListpriceCat2.add(coll.getPrice().get(i + 1));
tempListRatingCat1.add(coll.getRating().get(i));
tempListRatingCat2.add(coll.getRating().get(i + 1));
tempListYearCat1.add(coll.getYears().get(i));
tempListYearCat2.add(coll.getYears().get(i + 1));
}
setLastOffset(limit);
if (limit < LIST_SIZE) {
// return true;
return (getWrappedAdapter().getCount() < coll
.getDisplayNames().size());
} else {
return false;
}
} else {
return false;
}
}
#Override
protected void appendCachedData() {
#SuppressWarnings("unchecked")
// Activity activity = this;
// ArrayAdapter<String> arrAdapterNew =
// (ArrayAdapter<String>)getWrappedAdapter();
CategoryListLazyAdapter arrAdapterNewCategory = (CategoryListLazyAdapter) getWrappedAdapter();
// int listLen = tempList.size();
// int listLen = tempListNames.size();
countriesSubCat.addAll(tempListNamesCat);
imagesSubCat.addAll(tempListImagesCat);
mpgSubCat1.addAll(tempListmpgCat1);
mpgSubCat2.addAll(tempListmpgCat2);
priceSubCat1.addAll(tempListpriceCat1);
priceSubCat2.addAll(tempListpriceCat2);
ratingSubCat1.addAll(tempListRatingCat1);
ratingSubCat2.addAll(tempListRatingCat2);
YearSubCat1.addAll(tempListYearCat1);
YearSubCat2.addAll(tempListYearCat2);
arrAdapterNewCategory.notifyDataSetChanged();
/*Utility util = new Utility();
util.setListViewHeightBasedOnChildren(lvCategory);*/
/*
* for(int i=0; i<listLen; i++){ //
* arrAdapterNew.add(tempList.get(i)); }
*/
}
}
Thanks in adavance.
Try adding a ScrollView in the xml file.

cannot setvisibility in listview

Here is to control visibility of the layout
if (!(imagepath[i].toString().equals("no picture"))) {
try {
aURL = new URL("http://www.orientaldaily.com.my/"
+ imagepath[i]);
URLConnection conn = aURL.openConnection();
conn.connect();
InputStream is = conn.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
Bitmap bm = BitmapFactory.decodeStream(bis);
bis.close();
is.close();
layout_image.setVisibility(View.VISIBLE);
imageview.setVisibility(View.VISIBLE);
imageview.setScaleType(ScaleType.CENTER_CROP);
imageview.setImageBitmap(bm);
} catch (IOException e) {
Log.e("DEBUGTAG", "Remote Image Exception", e);
}
}
SimpleAdapter adapter = new SimpleAdapter(this, fillMaps,
R.layout.main_alllatestnewslist, from, to);
lv.setAdapter(adapter);
Here is to initialize it
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_alllatestnews);
lv = (ListView) findViewById(android.R.id.list);
RelativeLayout temp = (RelativeLayout)findViewById(R.id.layout_temp);
LayoutInflater liInflater = (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
temp.addView(liInflater.inflate(R.layout.main_alllatestnewslist, null));
Here is the main_alllatestnews.xml
<LinearLayout
android:id="#+id/layout_content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#id/layout_menu"
android:layout_below="#id/layout_title"
android:orientation="vertical" >
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
Here is the main_alllatestnewslist.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layout_temp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/background_news_list" >
<LinearLayout
android:id="#+id/layout_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10px"
android:layout_marginTop="10px" >
<ImageView
android:id="#+id/image_alllatestnewstitle"
android:layout_width="134px"
android:layout_height="80px"
android:src="#drawable/image_loading_failed_1"
android:visibility="invisible" />
</LinearLayout>
When i run this, it gave me Nullpointerexception at line
temp.addView(liInflater.inflate(R.layout.main_alllatestnewslist, null)); <-- inflater still null...
How to solve this?
Change
setContentView(R.layout.main_alllatestnews);
to
setContentView(R.layout.main_alllatestnewslist);
because layout_image is in layout main_alllatestnewslist
Edited:
LayoutInflater liInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
yourView.addView(liInflater.inflate(R.layout.main_alllatestnewslist, null))
something like that.
;

Categories

Resources