I have got the following code to set the values of the EditText at the header bar (master flow) but it failes and no values are assigned.
Would you please tell me how setText ?
The below is my code
(My Master Activity)
#SuppressWarnings("deprecation")
public class MainActivity extends Activity
{
private AsyncTask <Void , Void, Void> mRegisterTask ;
private String userid;
private String orderid;
...
View inflatedView = getLayoutInflater().inflate(R.layout.activity_main, null);
final EditText s = (EditText) inflatedView.findViewById(R.id.textView2);
userid = "99999";
s.setText(userid);
activity_main
<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:layout_margin="0dp"
android:background="#drawable/bg_with_header"
android:padding="0dp"
tools:context=".MainActivity" >
<TabHost
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="0dp"
android:padding="0dp" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="0dp"
android:orientation="vertical"
android:padding="0dp" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="82dp"
android:layout_margin="0dp"
android:layout_marginRight="50dp"
android:orientation="horizontal"
android:padding="0dp" >
<ImageView
android:id="#+id/logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="0dp"
android:src="#drawable/header_tv1231231231231bnvlogo" />
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="82dp"
android:layout_gravity="center"
android:layout_toLeftOf="#+id/headerLogin"
android:scrollbars="none" >
<TabWidget
android:id="#android:id/tabs"
android:layout_width="300dp"
android:layout_height="86dp"
android:layout_marginBottom="0dp"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
android:showDividers="none"
android:tabStripEnabled="false" />
</HorizontalScrollView>
<RelativeLayout
android:id="#+id/headerLogin"
android:layout_width="wrap_content"
android:layout_height="82dp"
android:orientation="horizontal" >
<EditText
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:background="#drawable/txtbg"
android:ems="10"
android:enabled="false"
android:focusable="true"
android:focusableInTouchMode="true"
android:padding=" 5dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#BDBDBD" />
<EditText
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="#+id/textView1"
android:background="#drawable/txtbg"
android:ems="10"
android:enabled="false"
android:focusable="true"
android:focusableInTouchMode="true"
android:padding="5dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#BDBDBD" />
<TextView
android:id="#+id/textVieasas2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textVieasas"
android:layout_alignBottom="#+id/textVieasas"
android:layout_toRightOf="#+id/textView2"
android:text="Last Login Date"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#FFFFFF" />
<TextView
android:id="#+id/textVieasas"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/textView2"
android:layout_alignLeft="#+id/textView2"
android:text="Sales Code"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#FFFFFF" />
</RelativeLayout>
</LinearLayout>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="0dp"
android:padding="0dp" />
</LinearLayout>
</TabHost>
you can also simple use this:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
EditText s = (EditText) findViewById(R.id.textView2);
userid = "99999";
s.setText(userid);
}
Do this way
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
EditText s = (EditText) findViewById(R.id.textView2);
userid = "99999";
s.setText(userid);
// or
View inflatedView = getLayoutInflater().inflate(R.layout.activity_main, null);
final EditText s = (EditText) inflatedView.findViewById(R.id.textView2);
userid = "99999";
s.setText(userid);
setContentView(inflatedView);
}
Related
I need to make the image that I get from database circular
I have made this code but I don't know how to complete it to make the image circular
please help
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_details);
name = (TextView) findViewById(R.id.names);
date = (TextView) findViewById(R.id.dates);
Story = (TextView) findViewById(R.id.story);
im = (ImageView) findViewById(R.id.img_car);
im.setScaleType(ImageView.ScaleType.FIT_XY);
//ScrollView scroller = new ScrollView(this);
//scroller.addView(Story);
Bundle extras = getIntent().getExtras();
int idf = extras.getInt("index");
Book selectedBook;
db = new SQLhelper(getApplicationContext());
// read the book with "id" from the database
selectedBook = db.readBook(++idf);
name.setText(selectedBook.getTitle());
date.setText(selectedBook.getdate());
Story.setText(selectedBook.getstory()+"\n \n ");
pname = selectedBook.getTitle();
test = selectedBook.getimage();
int id = getResources().getIdentifier("com.example.tarekhy:drawable/" + test, null, null);
im.setImageResource(id);
}
and this is xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="8dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="8dp"
android:background="#drawable/customborder">
<ImageView
android:id="#+id/img_car"
android:layout_width="70dp"
android:layout_height="50dp"
android:layout_marginBottom="5dp"
android:layout_marginRight="15dp"
android:layout_marginTop="5dp"
android:contentDescription="#null"
android:gravity="center_vertical"
android:onClick="viewbig"
/>
<RelativeLayout
android:id="#+id/imgs"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" >
<LinearLayout
android:id="#+id/layout_car_model"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:orientation="horizontal" >
<TextView
android:id="#+id/names"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold"
android:text="gfhbj"/>
</LinearLayout>
<LinearLayout
android:id="#+id/layout_car_color"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/layout_car_model"
android:orientation="horizontal" >
<TextView
android:id="#+id/dates"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="italic"
/>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
<ScrollView android:id="#+id/textAreaScroller"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_x="0px"
android:layout_y="25px"
android:scrollbars="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_below="#+id/fbedittext"
android:layout_marginTop="22dp"
android:id="#+id/story"
android:textStyle="bold"
android:layout_marginBottom="20px"
/>
</ScrollView>
"
</LinearLayout>
I think that I need to make a style
I tried to do this but I failed
Help please
You Need CircularImageView From CircularImageView
in xml file You have To Replace this code instead of Imageview :-<de.hdodenhof.circleimageview.CircleImageView
android:id ="#+id/img_car"
android:layout_width="160dp"
android:layout_height="160dp"
android:layout_centerInParent="true"
app:border_width="2dp"
app:border_color="#color/dark" />
In Activity File Replace This Code instead of Imageview:-
CircleImageView im= (CircleImageView) findViewById(R.id.img_car);
I have tried using FragmentTabHost. all went well, and has managed to show the tab well. but my fragment not showing layout of that class. I've tried using the TextView, but still did not appear.
please help me.
My FragmentActivity
public class ViewDetailAnak extends FragmentActivity{
private static String idanak;
private FragmentTabHost tabHost;
private static final String TRANS_SPEC = "";
private static final String US_SPEC = "";
private static final String TABU_SPEC = "";
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fro_single_item_anak);
tabHost = (FragmentTabHost)findViewById(android.R.id.tabhost);
tabHost.setup(this, getSupportFragmentManager(),android.R.id.tabcontent);
tabHost.addTab(
tabHost.newTabSpec(TRANS_SPEC)
.setIndicator(TRANS_SPEC, getResources().getDrawable(R.drawable.icon_trans)),
FROVDATransaksi.class, null);
tabHost.addTab(
tabHost.newTabSpec(US_SPEC)
.setIndicator(US_SPEC, getResources().getDrawable(R.drawable.icon_us)),
FROVDAUangsaku.class, null);
tabHost.addTab(
tabHost.newTabSpec(TABU_SPEC)
.setIndicator(TABU_SPEC, getResources().getDrawable(R.drawable.icon_tab)),
FROVDATabungan.class, null);
}
One of 3 fragment
public static class FROVDAUangsaku extends Fragment {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fro_vda_uangsaku, container, false);
return v;
}
}
and this is XML
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:orientation="vertical" >
<TableLayout
android:id="#+id/tableLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="14dp"
android:clipToPadding="true"
android:paddingTop="15dp" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/user1" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:paddingLeft="10dp" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="15.86"
android:orientation="vertical"
android:paddingLeft="10dp" >
<TextView
android:id="#+id/txtNama_FRO_Profil"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/nama" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingRight="10dp" >
<TextView
android:id="#+id/txNama_fra_profil"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical|center_horizontal"
android:text="Uang Saku"
android:textColor="#666666"
android:textSize="9dp" />
<TextView
android:id="#+id/txtJumlahAnak_FRO_Profil"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical|center_horizontal"
android:textColor="#000000"
android:textSize="12dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/txtnomuangsaku"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical|center_horizontal"
android:text="Tabungan"
android:textColor="#666666"
android:textSize="9sp" />
<TextView
android:id="#+id/saldotabungan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical|center_horizontal"
android:textColor="#000000"
android:textSize="12dp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="#+id/btnLogoutFRO_profilo"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_marginLeft="10dp"
android:gravity="center"
android:text="Edit Profile"
android:textColor="#000000"
android:textSize="12sp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</TableRow>
<View
android:layout_height="2dip"
android:layout_marginTop="5dp"
android:background="#666666" />
</TableLayout>
<android.support.v4.app.FragmentTabHost
android:id="#android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/tableLayout1">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TabWidget
android:id="#android:id/tabs"
android:layout_width="match_parent"
android:layout_height="38dp" />
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"/>
</LinearLayout>
</android.support.v4.app.FragmentTabHost>
ignore inside TableLayout. The only design. and I make fragmenttab under TableLayout
unfortunately my app crashes when this activity is being loaded:
public class ManagerActivity extends Activity implements OnClickListener {
private TabHost th;
private EditText addpray1;
private EditText addplace1;
private EditText addtime1;
private Button addpray1Button;
private EditText removepray1;
private EditText removeplace1;
private EditText removetime1;
private Button removepray1Button;
private EditText addpray2;
private EditText addplace2;
private EditText addtime2;
private Button addpray2Button;
private EditText removepray2;
private EditText removeplace2;
private EditText removetime2;
private Button removepray2Button;
private EditText addtitlemessage;
private EditText addinfomessage;
private Button addmessagebutton;
private EditText removetitlemessage;
private Button removemessagebutton;
private EditText addtitleevent;
private EditText addinfoevent;
private Button addeventbutton;
private EditText removetitleevent;
private Button removeeventbutton;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.manager);
th = (TabHost) findViewById(R.id.tabhost);
InitTabs(th);
InitFields();
addpray1Button.setOnClickListener(this);
removepray1Button.setOnClickListener(this);
addpray2Button.setOnClickListener(this);
removepray2Button.setOnClickListener(this);
addeventbutton.setOnClickListener(this);
removeeventbutton.setOnClickListener(this);
addmessagebutton.setOnClickListener(this);
removeeventbutton.setOnClickListener(this);
}
private void InitTabs(TabHost th){
th.setup();
TabSpec specs = th.newTabSpec("tag1");
specs.setContent(R.id.tab1);
specs.setIndicator("עדכון הודעות");
th.addTab(specs);
specs = th.newTabSpec("tag2");
specs.setContent(R.id.tab2);
specs.setIndicator("עדכון אירועים");
th.addTab(specs);
specs = th.newTabSpec("tag3");
specs.setContent(R.id.tab3);
specs.setIndicator("עדכון זמני השבת");
th.addTab(specs);
specs = th.newTabSpec("tag3");
specs.setContent(R.id.tab4);
specs.setIndicator("עדכון זמני יום חול");
th.addTab(specs);
}
private void InitFields() {
// TODO Auto-generated method stub
addpray1 = (EditText) findViewById(R.id.addPray1);
addplace1 = (EditText) findViewById(R.id.place1);
addtime1 = (EditText) findViewById(R.id.time1);
addpray1Button = (Button) findViewById(R.id.addPrayButton1);
removepray1 = (EditText) findViewById(R.id.removePray1);
removeplace1 = (EditText) findViewById(R.id.time_remove1);
removetime1 = (EditText) findViewById(R.id.place_remove1);
removepray1Button = (Button) findViewById(R.id.removePrayButton1);
addpray2 = (EditText) findViewById(R.id.pray2);
addplace2 = (EditText) findViewById(R.id.place2);
addtime2 = (EditText) findViewById(R.id.time2);
addpray2Button = (Button) findViewById(R.id.addPrayButton2);
removepray2 = (EditText) findViewById(R.id.removePray2);
removeplace2 = (EditText) findViewById(R.id.place_remove2);
removetime2 = (EditText) findViewById(R.id.time_remove2);
removepray2Button = (Button) findViewById(R.id.removePrayButton2);
addtitlemessage = (EditText) findViewById(R.id.titleMessage);
addinfomessage = (EditText) findViewById(R.id.messageInfo);
addmessagebutton = (Button) findViewById(R.id.addMessageButton);
removetitlemessage = (EditText) findViewById(R.id.removeMessage);
removemessagebutton = (Button) findViewById(R.id.removeMessageButton);
addtitleevent = (EditText) findViewById(R.id.addEvent);
addinfoevent = (EditText) findViewById(R.id.eventInfo);
addeventbutton = (Button) findViewById(R.id.addEventButton);
removetitleevent = (EditText) findViewById(R.id.removeEvent);
removeeventbutton = (Button) findViewById(R.id.removeEventButton);
}
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
}
and the xml file :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ProgressBar
android:id="#+id/progressbar"
style="#android:style/Widget.ProgressBar.Horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TabHost
android:id="#+id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TabWidget
android:id="#android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</TabWidget>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="#+id/tab1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="2" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
<TextView
android:id="#+id/addMessage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="הוספת הודעה"
android:textSize="25sp" />
<EditText
android:id="#+id/titleMessage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/addMessage"
android:hint="כותרת"
android:lines="1"
android:scrollHorizontally="false" />
<EditText
android:id="#+id/messageInfo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/titleMessage"
android:hint="מידע"
android:lines="4"
android:scrollHorizontally="true" />
<Button
android:id="#+id/addMessageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/messageInfo"
android:layout_centerInParent="true"
android:text="הוסף" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
<TextView
android:id="#+id/removeMessage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="הסרת הודעה"
android:textSize="25sp" />
<EditText
android:id="#+id/titleMessage_remove"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/removeMessage"
android:hint="כותרת"
android:lines="1"
android:scrollHorizontally="false" />
<Button
android:id="#+id/removeMessageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/titleMessage_remove"
android:layout_centerInParent="true"
android:text="הסר" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/tab2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="2" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
<TextView
android:id="#+id/addEvent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="הוספת אירוע"
android:textSize="25sp" />
<EditText
android:id="#+id/titleEvent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/addEvent"
android:hint="כותרת"
android:lines="1"
android:scrollHorizontally="false" />
<EditText
android:id="#+id/eventInfo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/titleEvent"
android:hint="מידע"
android:lines="4"
android:scrollHorizontally="true" />
<Button
android:id="#+id/addEventButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/eventInfo"
android:layout_centerInParent="true"
android:text="הוסף" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
<TextView
android:id="#+id/removeEvent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="הסרת אירוע"
android:textSize="25sp" />
<EditText
android:id="#+id/titleEvent_remove"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/removeEvent"
android:hint="כותרת"
android:lines="1"
android:scrollHorizontally="false" />
<Button
android:id="#+id/removeEventButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/titleEvent_remove"
android:layout_centerInParent="true"
android:text="הסר" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/tab3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="2" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
<TextView
android:id="#+id/addPray1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="הוספת תפילה"
android:textSize="25sp" />
<EditText
android:id="#+id/pray1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/addPray1"
android:hint="תפילה" />
<EditText
android:id="#+id/place1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/pray1"
android:hint="מקום" />
<EditText
android:id="#+id/time1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/place1"
android:hint="שעה" />
<Button
android:id="#+id/addPrayButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/time1"
android:layout_centerInParent="true"
android:text="הוסף" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
<TextView
android:id="#+id/removePray1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="הסרת תפילה"
android:textSize="25sp" />
<EditText
android:id="#+id/pray_remove1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/removePray1"
android:hint="תפילה" />
<EditText
android:id="#+id/place_remove1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/pray_remove1"
android:hint="מקום" />
<EditText
android:id="#+id/time_remove1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/place_remove1"
android:hint="שעה" />
<Button
android:id="#+id/removePrayButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/time_remove1"
android:layout_centerInParent="true"
android:text="הסר" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/tab4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="2" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
<TextView
android:id="#+id/addPray2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="הוספת תפילה"
android:textSize="25sp" />
<EditText
android:id="#+id/pray2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/addPray2"
android:hint="תפילה" />
<EditText
android:id="#+id/place2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/pray2"
android:hint="מקום" />
<EditText
android:id="#+id/time2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/place2"
android:hint="שעה" />
<Button
android:id="#+id/addPrayButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/time2"
android:layout_centerInParent="true"
android:text="הוסף" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
<TextView
android:id="#+id/removePray2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="הסרת תפילה"
android:textSize="25sp" />
<EditText
android:id="#+id/pray_remove2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/removePray2"
android:hint="תפילה" />
<EditText
android:id="#+id/place_remove2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/pray_remove2"
android:hint="מקום" />
<EditText
android:id="#+id/time_remove2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/place_remove2"
android:hint="שעה" />
<Button
android:id="#+id/removePrayButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/time_remove2"
android:layout_centerInParent="true"
android:text="הסר" />
</RelativeLayout>
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
</LinearLayout>
i guess it's because i'm loading a lot of views...
I'm also wanna to add a progress bar that works while the layout is loading until its done.
how can i fix that?
thanks :)
I have an android activity that when I launch sometimes (about 1 in 4 times) it only draws quarter or half the screen before showing it. When I change the orientation or press a button the screen draws properly.
I'm just using TextViews, Buttons, Fonts - no drawing or anything like that.
All of my code for initialising is in the onCreate(). In this method I'm loading a text file, of about 40 lines long, and also getting a shared preference. Could this cause a delay so that it can't draw the intent?
Thanks in advance if anyone has seen anything similar.
EDIT - I tried commenting out the loading of the word list, but it didn't fix the problem.
EDIT 2 - I didn't manage to resolve the problem, but managed to improve it by adding a timer right at the end of the onCreate. I set a low refresh rate and in the tick changed the text of one of the controls. This then seemed to redraw the screen and get rid of the black portions of the screen.
Here is the activity
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mainRelativeLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/blue_abstract_background" >
<RelativeLayout
android:id="#+id/relativeScore"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<TextView
android:id="#+id/ScoreLabel"
style="#style/yellowShadowText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:padding="10dip"
android:text="SCORE:"
android:textSize="18dp" />
/>
<TextView
android:id="#+id/ScoreText"
style="#style/yellowShadowText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#id/ScoreLabel"
android:padding="5dip"
android:text="0"
android:textSize="18dp" />
<TextView
android:id="#+id/GameTimerText"
style="#style/yellowShadowText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:minWidth="25dp"
android:text="0"
android:textSize="18dp" />
<TextView
android:id="#+id/GameTimerLabel"
style="#style/yellowShadowText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="#id/GameTimerText"
android:padding="10dip"
android:text="TIMER:"
android:textSize="18dp" />
/>
</RelativeLayout>
<RelativeLayout
android:id="#+id/relativeHighScore"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/relativeScore" >
<TextView
android:id="#+id/HighScoreLabel"
style="#style/yellowShadowText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:padding="10dip"
android:text="HIGH SCORE:"
android:textSize="16dp" />
<TextView
android:id="#+id/HighScoreText"
style="#style/yellowShadowText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/HighScoreLabel"
android:padding="10dip"
android:text="0"
android:textSize="16dp" />
</RelativeLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_below="#+id/relativeHighScore"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/linearMissing"
android:layout_width="fill_parent"
android:layout_height="80dp"
android:layout_gravity="center"
android:orientation="vertical" >
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#color/yellow_text" />
<TextView
android:id="#+id/MissingWordText"
style="#style/yellowShadowText"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center_horizontal"
android:layout_marginTop="25dp"
android:text="MSSNG WRD"
android:textSize="22dp"
android:typeface="normal" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#color/yellow_text" />
<TableLayout
android:id="#+id/buttonsTableLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TableRow
android:id="#+id/tableRow3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:paddingTop="5dp" >
<Button
android:id="#+id/aVowelButton"
android:layout_width="66dp"
android:layout_height="66dp"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="10dp"
android:layout_marginRight="5dp"
android:background="#drawable/blue_vowel_button"
android:text="#string/a"
android:textColor="#color/yellow_text"
android:textSize="30dp" />
<Button
android:id="#+id/eVowelButton"
android:layout_width="66dp"
android:layout_height="66dp"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="10dp"
android:layout_marginRight="5dp"
android:background="#drawable/blue_vowel_button"
android:text="#string/e"
android:textColor="#color/yellow_text"
android:textSize="30dp" />
</TableRow>
<TableRow
android:id="#+id/tableRow4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<Button
android:id="#+id/iVowelButton"
android:layout_width="66dp"
android:layout_height="66dp"
android:layout_gravity="center_horizontal"
android:layout_margin="5dp"
android:background="#drawable/blue_vowel_buttoni"
android:text="#string/i"
android:textColor="#color/yellow_text"
android:textSize="30dp" />
<Button
android:id="#+id/oVowelButton"
android:layout_width="66dp"
android:layout_height="66dp"
android:layout_gravity="center_horizontal"
android:layout_margin="5dp"
android:background="#drawable/blue_vowel_button"
android:text="#string/o"
android:textColor="#color/yellow_text"
android:textSize="30dp" />
<Button
android:id="#+id/uVowelButton"
android:layout_width="66dp"
android:layout_height="66dp"
android:layout_gravity="center_horizontal"
android:layout_margin="5dp"
android:background="#drawable/blue_vowel_button"
android:text="#string/u"
android:textColor="#color/yellow_text"
android:textSize="30dp" />
</TableRow>
</TableLayout>
<TextView
android:id="#+id/TimeToStartText"
style="#style/yellowShadowText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textSize="24dp" />
<Button
android:id="#+id/startButton"
style="#style/yellowShadowText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:background="#drawable/blue_button_menu"
android:gravity="center"
android:padding="10dip"
android:text="START!"
android:textSize="28dp" />
</LinearLayout>
</RelativeLayout>
And the OnCreate() and a few methods:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_game);
isNewWord = true;
m_gameScore = 0;
m_category = getCategoryFromExtras();
// loadWordList(m_category);
initialiseTextViewField();
loadHighScoreAndDifficulty();
setFonts();
setButtons();
setStartButton();
enableDisableButtons(false);
}
private void loadHighScoreAndDifficulty() {
//setting preferences
SharedPreferences prefs = this.getSharedPreferences(m_category, Context.MODE_PRIVATE);
int score = prefs.getInt(m_category, 0); //0 is the default value
m_highScore = score;
m_highScoreText.setText(String.valueOf(m_highScore));
prefs = this.getSharedPreferences(DIFFICULTY, Context.MODE_PRIVATE);
m_difficulty = prefs.getString(DIFFICULTY, NRML_DIFFICULTY);
}
private void initialiseTextViewField() {
m_startButton = (Button) findViewById(R.id.startButton);
m_missingWordText = (TextView) findViewById(R.id.MissingWordText);
m_gameScoreText = (TextView) findViewById(R.id.ScoreText);
m_gameScoreLabel = (TextView) findViewById(R.id.ScoreLabel);
m_gameTimerText = (TextView) findViewById(R.id.GameTimerText);
m_gameTimerLabel = (TextView) findViewById(R.id.GameTimerLabel);
m_timeToStartText = (TextView) findViewById(R.id.TimeToStartText);
m_highScoreLabel = (TextView) findViewById(R.id.HighScoreLabel);
m_highScoreText = (TextView) findViewById(R.id.HighScoreText);
}
private String getCategoryFromExtras() {
String category = "";
Bundle extras = getIntent().getExtras();
if (extras != null) {
category = extras.getString("category");
}
return category;
}
private void enableDisableButtons(boolean enable) {
Button button = (Button) findViewById(R.id.aVowelButton);
button.setEnabled(enable);
button = (Button) findViewById(R.id.eVowelButton);
button.setEnabled(enable);
button = (Button) findViewById(R.id.iVowelButton);
button.setEnabled(enable);
button = (Button) findViewById(R.id.oVowelButton);
button.setEnabled(enable);
button = (Button) findViewById(R.id.uVowelButton);
button.setEnabled(enable);
}
private void setStartButton() {
m_startButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
m_gameScore = 0;
updateScore();
m_startButton.setVisibility(View.GONE);
m_timeToStartText.setVisibility(View.VISIBLE);
startPreTimer();
}
});
}
i am using fragment in my application.there are 5 tabs.in 1 tab i need to inflate a list view on a button click.given below is my code for that tab.
public class TabStoreLocatorFragment extends Fragment implements OnClickListener {
private Button mapSwitcher;
private LinearLayout lastSelectedStoreButton;
private LinearLayout noSelectedStoreSection;
private TextView storeInfoName;
private TextView storeInfoAddress;
private TextView storeInfoCity;
private RelativeLayout phoneLocationButton;
private EditText searchStoreLocation;
private ListView storeList;
private ViewFlipper storeFlipper;
LinearLayout theLayout;
Store store;
#SuppressWarnings("static-access")
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
if (container == null) {
}
theLayout = (LinearLayout) inflater.inflate(
R.layout.tab_store_locator_layout, container, false);
phoneLocationButton = (RelativeLayout) theLayout.findViewById(R.id.phone_location_button);
mapSwitcher=(Button)theLayout.findViewById(R.id.switch_state_button);
lastSelectedStoreButton=(LinearLayout)theLayout.findViewById(R.id.last_selected_store_button);
noSelectedStoreSection=(LinearLayout)theLayout.findViewById(R.id.no_selected_store);
storeInfoName=(TextView)theLayout.findViewById(R.id.store_name);
storeInfoAddress=(TextView)theLayout.findViewById(R.id.store_address);
storeInfoCity=(TextView)theLayout.findViewById(R.id.store_city);
searchStoreLocation=(EditText)theLayout.findViewById(R.id.search_store);
storeFlipper = (ViewFlipper)theLayout.findViewById(R.id.store_flipper);
store=new Store();
store.setName("store1");
store.setAddress("california");
store.setCity("newyork");
store.setZipCode("23");
store.setState("california");
phoneLocationButton.setOnClickListener(this);
mapSwitcher.setOnClickListener(this);
lastSelectedStoreButton.setOnClickListener(this);
return theLayout;
}
#Override
public void onClick(View view) {
int id = view.getId();
if (id == R.id.phone_location_button) {
storeList = (ListView)storeFlipper.inflate(getActivity(), R.layout.store_list, storeFlipper);
storeFlipper.addView(storeList);
StoreAdapter adapter = new StoreAdapter(getActivity(), R.layout.store_list_item);
storeList.setAdapter(adapter);
}
else if(id == R.id.switch_state_button){
}
else{
}
}
}
i want to inflate storelist to storeFlipper.i tried to do that.but it is not working.given below is the corresponding layout for that tab.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#android:color/white" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/find_a_store_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="15dp"
android:layout_alignParentLeft="true"
android:text="#string/tab_find_a_store_title"
android:textColor="#android:color/black"
android:textSize="18sp"
android:textStyle="bold" />
<Button android:id="#+id/switch_state_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:background="#drawable/switch_selector" />
</RelativeLayout>
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#E8E2D3" />
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#C5BFAD" />
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout android:id="#+id/last_selected_store_button" android:baselineAligned="false"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
style="#android:style/Widget.Button"
android:orientation="horizontal"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:paddingRight="5dp"
android:background="#drawable/last_selected_store_background" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:textColor="#8E8672"
android:text="#string/last_selected_store_label"
android:textSize="12sp" />
</RelativeLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="5dp"
android:orientation="vertical" >
<TextView android:id="#+id/store_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#android:color/black"
android:textSize="12sp" />
<TextView android:id="#+id/store_address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#android:color/black"
android:textSize="12sp" />
<TextView android:id="#+id/store_city"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#android:color/black"
android:textSize="12sp" />
</LinearLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:background="#drawable/arrow" />
</RelativeLayout>
</LinearLayout>
<LinearLayout android:id="#+id/no_selected_store"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:paddingRight="5dp"
android:background="#drawable/last_selected_store_background" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:textColor="#8E8672"
android:text="#string/no_selected_store_label"
android:textSize="12sp" />
</LinearLayout>
</FrameLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dp" >
<EditText android:id="#+id/search_store"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:singleLine="true"
android:textSize="14sp"
android:hint="#string/search_store_placeholder"
android:layout_toLeftOf="#+id/phone_location_button"
android:background="#drawable/search_store_background" />
<RelativeLayout android:id="#id/phone_location_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:background="#drawable/get_location_background" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/get_location" />
</RelativeLayout>
</RelativeLayout>
<ViewFlipper android:id="#+id/store_flipper"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
can anybody help me to inflate the list to flipper.
it is simple.just put this code.
storeList = (ListView) inflater.inflate(R.layout.store_list, null);
it is working