Thanks Mark
So my code is complete but I have an issu when I want to choice the
icon on getView().
I want to choice my icon like thre following code. But I have to use
the oClient object to find Flag.
oClient is on TabVoicemail class.
But IconicAdapter is a class and I can't touch oClient.
So I try to touch oClient because IconicAdapter is into my
TabVoicemail class.
but I have a : 08-11 12:00:02.176: ERROR/AndroidRuntime(1169):
java.lang.NullPointerException
My java code :
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
package com.dany.android.socketinterface;
import java.io.IOException;
import java.util.ArrayList;
import android.app.Activity;
import android.app.ListActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
public class TabVoicemail extends ListActivity {
public TextView selection;
public ArrayList<String> mStrings = new ArrayList<String>();
private Button effacer, repondre;
private static final String TAG = "MyActivity";
public Client oClient;
public void setClient(Client oClient)
{
this.oClient = oClient;
}
/*public Client getClient()
{
return oClient;
}*/
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.content_tab_voicemail);
/****************************** CLIENT (début)
******************************/
// Création de l'objet Client permettant de se connecter au serveur
IMAP
Client oClient = new Client();
try {
// Connection et récupération des messages
oClient.start();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
TabVoicemail mTabVoicemail = new TabVoicemail();
mTabVoicemail.setClient(oClient);
/* String flag = "empty";
flag = mTabVoicemail.oClient.getMsg(0).getFlag();
Log.v(TAG,"Flag (0) dans la classe IconicAdapter : " + flag);
*/
/****************************** CLIENT (fin)
******************************/
/****************************** GERER LES BOUTONS (début)
******************************/
effacer = (Button)findViewById(R.id.effacer);
repondre = (Button)findViewById(R.id.repondre);
effacer.setOnClickListener(new Button.OnClickListener()
{
public void onClick(View v)
{
// Action lorsque je presse le bouton Effacer
Log.v(TAG, "J'ai bien appuyé sur le bouton
effacer");
}
});
repondre.setOnClickListener(new Button.OnClickListener()
{
public void onClick(View v)
{
// Action lorsque je presse le bouton Répondre
Log.v(TAG, "J'ai bien appuyé sur le bouton
repondre");
}
});
/****************************** GERER LES BOUTONS (fin)
******************************/
/****************************** GERER LES INFOS LIST VOICEMAIL
(début) ******************************/
// ListView list=(ListView) findViewById(R.id.ListView01);
//ArrayList<String> mStrings = new ArrayList<String>();
ArrayAdapter<String> mAdapter = new ArrayAdapter<String>
(this,R.layout.row_voicemail, R.id.label, mStrings);
/*mAdapter.add("itemAdd0");
Log.v(TAG, mAdapter.getItem(0)); */
// Récupérer les infos pour chaque message ex: Date
for(int i=0 ; i < oClient.getnbMess() ; i++)
{
mAdapter.add(oClient.getMsg(i).getDate());
String flag = "empty";
flag = oClient.getMsg(i).getFlag();
Log.v(TAG,"Flag (" + i +") dans la classe TabVoicemail
: " + flag);
}
//list.setAdapter(mAdapter);
//setListAdapter(mAdapter);
setListAdapter(new IconicAdapter(this));
selection=(TextView)findViewById(R.id.selection);
/****************************** GERER LES INFOSLIST VOICEMAIL (fin)
******************************/
}
public void onListItemClick(ListView parent, View v, int position,
long id) {
selection.setText(mStrings.get(position));
}
class IconicAdapter extends ArrayAdapter {
Activity context;
IconicAdapter(Activity context) {
super(context, R.layout.row_voicemail, mStrings);
this.context=context;
}
public View getView(int position, View convertView, ViewGroup
parent)
{
LayoutInflater inflater=context.getLayoutInflater();
View row=inflater.inflate(R.layout.row_voicemail, null);
TextView label=(TextView)row.findViewById(R.id.label);
label.setText(mStrings.get(position));
ImageView icon=(ImageView)row.findViewById(R.id.icon);
Log.v(TAG,"Valeur de position : " + position);
String flag =
"empty";
*******************************************************************************
flag = oClient.getMsg(0).getFlag();
* // here the NullPointerException with oClient.getMsg(0).getFlag()
*
Log.v(TAG,"Flag (0) dans la classe IconicAdapter : " +
flag);
*******************************************************************************
if(oClient.getMsg(position).getFlag() == "Seen")
{
icon.setImageResource(R.drawable.check32);
}
else if(oClient.getMsg(position).getFlag() == "NewMsg")
{
icon.setImageResource(R.drawable.delete);
}
else if(oClient.getMsg(position).getFlag() == "Deleted")
{
icon.setImageResource(R.drawable.delete);
}
else
{
icon.setImageResource(R.drawable.delete);
}
/* if (mStrings.get(position).length()>4) {
icon.setImageResource(R.drawable.delete);
}
else {
icon.setImageResource(R.drawable.check32);
}*/
return(row);
}
}
}
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
So my question is How I can use my oClient into my IconicAdapter
class without pass Oclient as parameter.
Just information: my line code " oClient.getMsg(i).getFlag() " run
into my TabVoicemail class and have no error.
Dany
On Aug 10, 4:47 pm, Mark Murphy <[email protected]> wrote:
> Mark Murphy wrote:
> > Please re-read the PDF I linked to several messages ago. You can get
> > source code that matches that excerpt from:
>
> >http://commonsware.com/Android
>
> > (click on the Source Code link, and look in the FancyLists directory in
> > the ZIP file)
>
> Also, you might wish to read:
>
> http://developer.android.com/reference/android/app/ListActivity.html
>
> "To do this, your own view MUST contain a ListView object with the id
> @android:id/list".
>
> You appear to be confusing row layouts and the overall activity layout.
>
> --
> Mark Murphy (a Commons
> Guy)http://commonsware.com|http://twitter.com/commonsguy
>
> Warescription: Three Android Books, Plus Updates, $35/Year
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---