How to update layouts in an .xml dynamically from the code?

Put your problem here if it does not fit any of the other categories.

How to update layouts in an .xml dynamically from the code?

Postby Jitendra Kumar » Wed Apr 09, 2008 1:40 pm

Hi! This Jitendra .

I have desined a MessageBox application where user can read messages, write messages and can save them in android. I desined the messages in an .xml file and for deletion i m setting the visibility modes only but when i returning in the main activity the deleted message is still visible .

Here r some code:

package com.google.android.GPSDemo;



import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageButton;

public class Draft extends Activity {

AlertDialog.Builder alert =new AlertDialog.Builder(Draft.this);


public static ImageButton mRead;
public static ImageButton mDelete;
public static ImageButton mQuit;

public static View User1;
public static View user2;
public static View user3;
public static View user4;
public static View user5;
public static View view1updown;
public static int flagForFirstLet=0;
public static int flagForFirstDown=0;
public static int flagForInfo=0;
public static int flagForFirstRight=0;

public void onCreate(Bundle icicle) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_NO_STATUS_BAR,
WindowManager.LayoutParams.FLAG_NO_STATUS_BAR);
super.onCreate(icicle);
setContentView(R.layout.saved_msgs);

if( globalclass.mDeletedItems == 1)
globalclass.mViewDeleted.setVisibility(View.GONE);

User1=(View)findViewById(R.id.player1);
User1.setOnClickListener(User1ClickListener);

User1.setOnFocusChangeListener(playerFocusListener);
flagForInfo=0;
flagForFirstLet=0;
flagForFirstDown=0;
flagForFirstRight=0;


user2=(View)findViewById(R.id.player2);
user2.setOnFocusChangeListener(playerFocusListener);
user2.setOnClickListener(User2ClickListener);

user3=(View)findViewById(R.id.player3);
user3.setOnFocusChangeListener(playerFocusListener);
user3.setOnClickListener(User3ClickListener);

user4=(View)findViewById(R.id.player4);
user4.setOnFocusChangeListener(playerFocusListener);
user4.setOnClickListener(User4ClickListener);

user5=(View)findViewById(R.id.player5);
user5.setOnFocusChangeListener(playerFocusListener);
user5.setOnClickListener(User5ClickListener);

view1updown=User1;





mRead = (ImageButton)findViewById(R.id.user_messages);
mRead.setOnClickListener(mReadClickListener);
mRead.setOnFocusChangeListener(mReadFocusListener);

mDelete = (ImageButton)findViewById(R.id.add);
mDelete.setOnClickListener(mDeleteClickListener);
mDelete.setOnFocusChangeListener(mDeleteFocusListener);

mQuit = (ImageButton)findViewById(R.id.exit);
mQuit.setOnClickListener(mQuitClickListener);
mQuit.setOnFocusChangeListener(mQuitFocusListener);

}

public static View.OnFocusChangeListener playerFocusListener =
new View.OnFocusChangeListener() {

public void onFocusChanged(View arg0,boolean arg1) {
if(arg1) {


arg0.setBackground(R.color.color1);


} else {

arg0.setBackground(R.color.color);

}
}
};





public static ImageButton.OnFocusChangeListener mReadFocusListener =
new ImageButton.OnFocusChangeListener() {

public void onFocusChanged(View arg0,boolean arg1) {
if(arg1) {
arg0.setBackground(R.drawable.read_active);


} else {
arg0.setBackground(R.drawable.read_inactive);

}
}
};
public static ImageButton.OnFocusChangeListener mDeleteFocusListener=
new ImageButton.OnFocusChangeListener() {

public void onFocusChanged(View arg0,boolean arg1) {
if(arg1) {
arg0.setBackground(R.drawable.delete_active);



} else {
arg0.setBackground(R.drawable.delete_inactive);

}
}
};

public static ImageButton.OnFocusChangeListener mQuitFocusListener =
new ImageButton.OnFocusChangeListener() {

public void onFocusChanged(View arg0,boolean arg1) {
if(arg1) {
arg0.setBackground(R.drawable.back_active);


} else {
arg0.setBackground(R.drawable.back_inactive);

}
}
};





public static View.OnClickListener User1ClickListener=
new View.OnClickListener()
{
public void onClick(View arg0){

view1updown.setBackground(R.color.color);
User1.requestFocus();
view1updown=User1;
view1updown.setBackground(R.color.color1);


}
};
public static View.OnClickListener User2ClickListener=
new View.OnClickListener()
{
public void onClick(View arg0){

view1updown.setBackground(R.color.color);
user2.requestFocus();
view1updown=user2;
view1updown.setBackground(R.color.color1);


}
};
public static View.OnClickListener User3ClickListener=
new View.OnClickListener()
{
public void onClick(View arg0){

view1updown.setBackground(R.color.color);
user3.requestFocus();
view1updown=user3;
view1updown.setBackground(R.color.color1);


}
};
public static View.OnClickListener User4ClickListener=
new View.OnClickListener()
{
public void onClick(View arg0){

view1updown.setBackground(R.color.color);
user4.requestFocus();
view1updown=user4;
view1updown.setBackground(R.color.color1);


}
};
public static View.OnClickListener User5ClickListener=
new View.OnClickListener()
{
public void onClick(View arg0){

view1updown.setBackground(R.color.color);
user5.requestFocus();
view1updown=user5;
view1updown.setBackground(R.color.color1);


}
};

public ImageButton.OnClickListener mQuitClickListener=
new ImageButton.OnClickListener()
{
public void onClick(View arg0){

finish();
}
};
public ImageButton.OnClickListener mReadClickListener=
new ImageButton.OnClickListener()
{
public void onClick(View arg0){
mRead.setFocusableInTouchMode(true);
mRead.requestFocus();
Intent int1 = new Intent(Draft.this, Read.class);
startSubActivity(int1,0);
view1updown.setBackground(R.color.color);

}
};

public ImageButton.OnClickListener mDeleteClickListener=
new ImageButton.OnClickListener()
{
public void onClick(View arg0){
mDelete.setFocusableInTouchMode(true);
mDelete.requestFocus();

alert.setMessage("Are you sure? ");
alert.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {

view1updown.setVisibility(View.GONE) ;
globalclass.mViewDeleted = view1updown;
globalclass.mDeletedItems =1;


}
});
alert.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {

setResult(RESULT_OK); }


});
alert.show();
}
};
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {
flagForFirstRight=0;
flagForFirstLet=0;
if(flagForFirstDown==0)
{
User1.requestFocus();
User1.setBackground(R.color.color1);
flagForFirstDown=1;
}
else
{

View view1 =this.getCurrentFocus();
view1updown=view1.focusSearch(130);
view1updown.requestFocus();
//setting focus to first User
if(view1updown==mQuit)
{
User1.requestFocus();
view1updown=User1;
}
}
return true;
}

if(keyCode == KeyEvent.KEYCODE_DPAD_UP) {

flagForFirstDown=0;
flagForFirstRight=0;
flagForFirstLet=0;
View view1=this.getCurrentFocus();
//For Fading out
view1updown.setBackground(R.color.color);
flagForInfo=0;
if(view1==User1)
{
User1.requestFocus();
view1updown=User1;
view1updown.setBackground(R.color.color1);
}
else
{
view1updown=view1.focusSearch(33);
view1updown.requestFocus();
}
return true;
}
if(keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) {


//For First Time
flagForFirstDown=0;
if(flagForFirstRight==0)
{
mRead.requestFocus();
//view1updown.setBackgroundColor(R.color.color1);
flagForFirstRight=1;
}
else
{
view1updown.setBackground(R.color.color1);
View view1=this.getCurrentFocus();
if(view1==mDelete)
mDelete.requestFocus();
else
{
View view2=view1.focusSearch(66);
view2.requestFocus();
}
}
return true;
}

if(keyCode == KeyEvent.KEYCODE_DPAD_LEFT) {


flagForFirstDown=0;
//For First Time
if(flagForFirstLet==0)
{
mQuit.requestFocus();
view1updown.setBackground(R.color.color1);
flagForFirstLet=1;
}
else
{
View view1=this.getCurrentFocus();
if(view1==mQuit)
mQuit.requestFocus();
else
{
View view2=view1.focusSearch(17);
view2.requestFocus();
}
}
return true;
}

return true;


}


}
Jitendra Kumar
Developer
Developer
 
Posts: 49
Joined: Thu Mar 06, 2008 7:55 am
Location: Bangalore

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Google [Bot] and 17 guests