Re: [android-developers] How to check the current contentView?

2012-05-15 Thread Brian Collo Gonçalves
Maybe using a static var to maintain the view you're using and get the
value in any other point you need to validate it.

2012/5/15 Justin Anderson magouyaw...@gmail.com

 This is not the typical Android workflow, so I highly recommend you don't
 do this...  But, if you are dead set on this kind of behavior, do the
 following:

1. Put all your main views you want in either a ViewFlipper (or
ViewSwitcher if there are only 2)
2. After calling setContentView, get a reference to the main views by
calling findViewById
3. When the back button is pressed check the current view of the
ViewFlipper or ViewSwitcher against the references you saved in step 2


 Thanks,
 Justin Anderson
 MagouyaWare Developer
 http://sites.google.com/site/magouyaware


 On Tue, May 15, 2012 at 4:05 AM, Narendra Singh Rathore 
 nsr.curi...@gmail.com wrote:

 Hi all,
 Is this possible to check the current contentView?

 As in my code, I am using a single activity, along with three different
 content views (using setContentView()), which I am changing according to my
 requirement.
 All is working fine till now.

 Now, what I want is that - when *clicking the back button, I want to
 check the current view (content view)*, and proceed further depending on
 the view.

 How can I achieve this if it is possible?


 Here is my java code, as follows:



 package com.test;


 import android.app.Activity;
 import android.os.Bundle;
 import android.util.Log;
 import android.view.View;
 import android.view.View.OnClickListener;
 import android.widget.AdapterView;
 import android.widget.AdapterView.OnItemClickListener;
 import android.widget.ArrayAdapter;
 import android.widget.Button;
 import android.widget.ListView;

 public class Test_appActivity extends Activity implements
 OnClickListener, OnItemClickListener{
 /** Called when the activity is first created. */
 ListView lv;
 Button btn1,btn2;
 String[] str=new String[]{one,two};
 @Override
 public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
first_view();

 }

 public void first_view()
 {
  setContentView(R.layout.main);
  lv=(ListView)findViewById(android.R.id.list);
  lv.setTextFilterEnabled(true);
  ArrayAdapterString adapter= new
 ArrayAdapterString(getApplicationContext(),
 android.R.layout.simple_list_item_1,str);
 lv.setAdapter(adapter);
 lv.setOnItemClickListener(this);
 }

 public void onClick(View v) {
 first_view();

 }

 //@Override
 //public void onBackPressed() {
 //
 if(findViewById(android.R.id.content).equals((View)this.findViewById(R.layout.one))
 //||
 findViewById(android.R.id.content).equals((View)this.findViewById(R.layout.two)))

 //{
 //first_view();
 //}
 //else
 //{super.onBackPressed();
 //}
 //}

 public void onItemClick(AdapterView? arg0, View arg1, int arg2,
 long arg3) {

 if(arg2==0)
 {
 setContentView(R.layout.one);
 btn1=(Button)findViewById(R.id.btn);
 btn1.setOnClickListener(Test_appActivity.this);
 }
 else
 {
 setContentView(R.layout.two);
 btn2=(Button)findViewById(R.id.btn1);
 btn2.setOnClickListener(Test_appActivity.this);
 }
 }


 }


 Please, help me out in this.

 With Regards,
 Narendra

 --
 You received this message because you are subscribed to the Google
 Groups Android Developers group.
 To post to this group, send email to android-developers@googlegroups.com
 To unsubscribe from this group, send email to
 android-developers+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en


  --
 You received this message because you are subscribed to the Google
 Groups Android Developers group.
 To post to this group, send email to android-developers@googlegroups.com
 To unsubscribe from this group, send email to
 android-developers+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en




-- 
*-*
*Brian Collo Gonçalves*
Líder de Sistemas
*NGM Business Solution*

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Parcelable encountered IOException writing serializable object - Object serializable with array of another serializable

2012-05-10 Thread Brian Collo Gonçalves
I have 2 serializable classes as follow:

@SuppressWarnings(serial)
public class Musicas implements Serializable {
private String musica;
private String link;
public Musicas(String musica, String link) {
super();
this.musica = musica;
this.link = link;
}
public String getMusica() {
return musica;
}
public void setMusica(String musica) {
this.musica = musica;
}
public String getLink() {
return link;
}
public void setLink(String link) {
this.link = link;
}
}




@SuppressWarnings(serial)
public class CDs implements Serializable {
private Drawable Picture;
private String Descricao;
private int idCD;
private ArrayListMusicas musicas;
public ArrayListMusicas getMusicas() {
return musicas;
}
public void setMusicas(ArrayListMusicas musicas) {
this.musicas = musicas;
}
public int getIdCD() {
return idCD;
}
public void setIdCD(int idCD) {
this.idCD = idCD;
}
public Drawable getPicture() {
return Picture;
}
public void setPicture(Drawable picture) {
Picture = picture;
}
public String getDescricao() {
return Descricao;
}
public void setDescricao(String descricao) {
Descricao = descricao;
}
public CDs(Drawable drawable, String descricao, int idcd) {
super();
Picture = drawable;
Descricao = descricao;
idCD = idcd;
}
public CDs(Drawable picture, String descricao, int idCD,
ArrayListMusicas musicas) {
this(picture, descricao, idCD);
setMusicas(musicas);
}
}



Where my CD Class have an ArrayList of Musics.
In my activity, I load the data from a Json to make a gallery of CDs
and selecting the CD i have the following code to pass the CD-Musics
to a new activity.

ArrayListCDs cds = new ArrayListCDs();
ArrayListMusicas musicas = new ArrayListMusicas();
JSONObject json = new JSONObject(sb.toString());
for (int i=1; i = 
json.getJSONObject(cds).length()-1; i++) {
JSONArray jarrayfilho =
json.getJSONObject(cds).getJSONArray(String.valueOf(i));
ArrayListMusicas musicas1 = new 
ArrayListMusicas();
for(int j = 0; j  
jarrayfilho.length(); j++)
{
musicas1.add(new Musicas(

jarrayfilho.getJSONObject(j).getString(NOME).toString(),

jarrayfilho.getJSONObject(j).getString(LINK).toString()));
}
musicas = musicas1;
cds.add(new CDs(
ImageOperations(this,
jarrayfilho.getJSONObject(0).getString(IMG).toString()),

jarrayfilho.getJSONObject(0).getString(CD).toString(), i,
musicas
)
);
gallery.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView? arg0, View arg1, 
int arg2,
long arg3) {
Intent musicas = new Intent(arg1.getContext(),
MusicasActivity.class);
musicas.putExtra(cd, cds.get(arg2));
startActivity(musicas);
}
});


But when I call the click event, I get the error: Parcelable
encountered IOException writing serializable object

Can anyone guide me through this? I have tried everything I found on
internet but no clues. What I found that may solve is create a static
class/properties, but I don't want to reach this aproach since it's
not recomended for memory issues and all.

Best Regards.

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en