I have this weird issue with my rating bar stars.
This is my app in vertical position
This is my app in horizontal position
As you can see the stars completely change
This is my xml file:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:background="#drawable/main"
tools:context="com.example.draganam.blankapp.Nivo1Activity">
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:shrinkColumns="1,0" android:stretchColumns="0,1">
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="50dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/slika0"
android:src="#drawable/becutan1"
android:layout_column="0"
android:layout_marginRight="40px" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/slika1"
android:src="#drawable/blizoo1"
android:layout_column="1" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<RatingBar
android:id="#+id/rb0"
style="?android:attr/ratingBarStyleIndicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numStars="5"
android:stepSize="1.0"
android:isIndicator="true"
android:scaleX="0.7"
android:scaleY="0.7"/>
<RatingBar
android:id="#+id/rb1"
style="?android:attr/ratingBarStyleIndicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numStars="5"
android:stepSize="1.0"
android:isIndicator="true"
android:scaleX="0.7"
android:scaleY="0.7"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="50dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/slika2"
android:src="#drawable/brilijant1"
android:layout_column="0"
android:layout_marginRight="40px" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/slika3"
android:src="#drawable/vitaminka1"
android:layout_column="1" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<RatingBar
android:id="#+id/rb2"
style="?android:attr/ratingBarStyleIndicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numStars="5"
android:stepSize="1.0"
android:isIndicator="true"
android:scaleX="0.7"
android:scaleY="0.7"/>
<RatingBar
android:id="#+id/rb3"
style="?android:attr/ratingBarStyleIndicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numStars="5"
android:stepSize="1.0"
android:isIndicator="true"
android:scaleX="0.7"
android:scaleY="0.7"/>
</TableRow>
</TableLayout>
</RelativeLayout>
This is my java code:
Context ctx2 = this;
String[][] arrayWithInformations = new String[5][];
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_nivo1);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
DatabaseOperations databaseOperations = new DatabaseOperations(ctx2);
Cursor cursorLogo = databaseOperations.getInformationsForLogos(databaseOperations);
// looping through all rows and adding to list
Integer i = 0;
if (cursorLogo.moveToFirst()) {
do {
String[] helperArray = {cursorLogo.getString(0),cursorLogo.getString(1),cursorLogo.getString(2),cursorLogo.getString(3),
cursorLogo.getString(4),cursorLogo.getString(5)};
arrayWithInformations[i] = helperArray;
i++;
} while (cursorLogo.moveToNext());
}
int firstRating = Integer.parseInt(arrayWithInformations[0][4]);
int secondRating = Integer.parseInt(arrayWithInformations[1][4]);
int thirdRating = Integer.parseInt(arrayWithInformations[2][4]);
int fourthRating = Integer.parseInt(arrayWithInformations[3][4]);
RatingBar rb0 = (RatingBar) findViewById(R.id.rb0);
rb0.setRating(firstRating);
RatingBar rb1 = (RatingBar) findViewById(R.id.rb1);
rb1.setRating(secondRating);
RatingBar rb2 = (RatingBar) findViewById(R.id.rb2);
rb2.setRating(thirdRating);
RatingBar rb3 = (RatingBar) findViewById(R.id.rb3);
rb3.setRating(fourthRating);
I get the rating values from database file and everything works fine , the stars are ok but when I rotate the phone they are all wrong. I know that when u rotate your phone the current activity gets loaded again, but it's the same code and it loads wrong. Maybe it's multiplying the stars.. I may sound funny but I have no idea what is going wrong. Someone please give me a lead..
I found out the problem !
android:shrinkColumns="1,0" android:stretchColumns="0,1"
Setting this to the TableLayout caused this strange issue.
Thanks everyone for your interest in helping me ..
Related
I am using android studio. Code Java. I bring the data in the json file to listview. When I press the increase and decrease button, I want to bring it to the textview. I just want to increase or decrease the number of products I click. I couldn't access the buttons and textview inside the listview. How can I do it?
try {
JSONObject obj=new JSONObject(LoadFromJsonAssets());
Resources resources = context.getResources();
JSONArray array =obj.getJSONArray("domestic");
HashMap<String,String> list;
ArrayList<HashMap<String,String>> arrayList=new ArrayList<>();
for (int i=0;i<array.length();i++){
JSONObject o=array.getJSONObject(i);
String productName=o.getString("productName");
String productPrice=o.getString("productPrice");
String productPic=o.getString("productPic");
final int resourceId = resources.getIdentifier(productPic, "drawable", context.getPackageName());
Drawable drawable = resources.getDrawable(resourceId);
Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), resourceId);
list= new HashMap<>();
list.put("productName",productName);
list.put("productPrice",productPrice);
list.put("productPic",Integer.toString(resourceId) );
arrayList.add(list);
}
final ListAdapter adapter= new SimpleAdapter(this,arrayList,R.layout.list_view_design,new String[]{"productName","productPrice","productPic"},new int[]{R.id.productName,R.id.productPrice,R.id.productPic});
listView.setAdapter(adapter);
listview design:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:orientation="vertical"
android:layout_margin="10dp"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="100dp">
<ImageView
android:layout_marginLeft="3dp"
android:id="#+id/productPic"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_alignParentStart="true"
android:layout_centerInParent="true">
</ImageView>
<LinearLayout
android:layout_marginLeft="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginRight="25dp"
android:layout_toLeftOf="#+id/lin2"
android:layout_toRightOf="#id/productPic"
android:orientation="vertical">
<TextView
android:id="#+id/productName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Product Name"
android:textSize="20dp"
android:textStyle="bold"></TextView>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/productPrice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="Product price"></TextView>
<TextView
android:id="#+id/turkishlira"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:layout_marginTop="5dp"
android:text="₺"></TextView>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/lin2"
android:orientation="horizontal"
android:layout_alignParentRight="true"
android:layout_centerInParent="true"
android:layout_marginRight="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/decreasing "
android:layout_marginRight="10dp"
android:src="#drawable/negative"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</ImageView>
<TextView
android:layout_gravity="center"
android:id="#+id/counterrrr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:textSize="15dp"
></TextView>
<ImageView
android:id="#+id/Increasing"
android:layout_marginLeft="10dp"
android:src="#drawable/positive"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</ImageView>
</LinearLayout>
</RelativeLayout>
Sorry but I cannot comment. Does the below not work?
Find it by:
final TextView textViewCounter = (TextView) rowView.findViewById(R.id.counterrrr);
and then set the text as needed:
// could be wrongly typed, just from the top of my head.
String currentCount = textViewCounter.getText();
int newCount = Integer.parseInt(currentCount) +/- 1;
textViewCounter.setText(String.valueOf(newCount));
I am creating a simple tasklist app, and I want to programmatically add a TextView to an embedded LinearLayout. However, it is not showing up for some reason.
I try to add the TextView in MainActivity (irrelevant code removed).
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
setIntent(intent);
processExtraData();
}
private void processExtraData(){
Integer hours = 4;
Integer minutes = 35;
Integer seconds = 0;
LinearLayout linearLayout = (LinearLayout) findViewById(R.id.linlayout);
TextView txt1 = new TextView(this);
final float scale = this.getResources().getDisplayMetrics().density;
int pixels = (int) (64 * scale + 0.5f);
ViewGroup.LayoutParams params = new LinearLayout.LayoutParams(0, pixels, 1f);
txt1.setLayoutParams(params); txt1.setText(hours.toString()+":"+minutes.toString()+":"+seconds.toString());
linearLayout.addView(txt1);
}
The embedded LinearLayout is declared in activity_main:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app ="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Super Reminder App!"
android:textAppearance="#style/TextAppearance.AppCompat.Large" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:layout_marginBottom="12dp"
android:orientation="horizontal">
<EditText
android:id="#+id/taskAdd"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3.5"
android:hint="New Task" />
<Button
android:id="#+id/add"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1.5"
android:text="Add Task" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="12.5"
android:orientation="horizontal">
<ListView
android:id="#+id/tasks"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2.5"/>
<LinearLayout
android:id="#+id/linlayout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:orientation="vertical"/>
</LinearLayout>
<Button
android:id="#+id/clearButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:text="Clear All" />
</LinearLayout>
I have already tested and made sure that onNewIntent and processExtraData are called. No errors are thrown either. Could this be a GUI issue? Any help would be greatly appreciated.
I'm just an beginner.
I'm unable to provide equal space between Item Name and quantity. I want Item Name to occupy space available.
I had tired using setGravity and setColumnStretchable but I'm unable to provide equal space.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<TableLayout
android:id="#+id/Table_Text_View"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<TableRow>
<TextView
android:id="#+id/Item_Name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:text="Item Name" />
<TextView
android:id="#+id/quantity"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Quantity" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Item Purchase" />
</TableRow>
</TableLayout>
</ScrollView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/Edit_Text_View1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Name of Item"
android:imeOptions="actionNext"
android:inputType="textMultiLine" />
<EditText
android:id="#+id/Edit_Text_View2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/Edit_Text_View1"
android:hint="Quantity"
android:imeOptions="actionDone"
android:inputType="number" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_toRightOf="#id/Edit_Text_View2"
android:onClick="doneClick"
android:text="Done" />
</RelativeLayout>
public void doneClick(View view) {
EditText editTextView1 = (EditText) findViewById(R.id.Edit_Text_View1);
String itemTextView1 = editTextView1.getText().toString();
EditText editTextView2 = (EditText) findViewById(R.id.Edit_Text_View2);
String itemTextView2 = editTextView2.getText().toString();
TableLayout table = (TableLayout) findViewById(R.id.Table_Text_View);
TableRow row = new TableRow(this);
TableRow.LayoutParams lay = new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT);
row.setLayoutParams(lay);
TextView itemName = new TextView(this);
TextView quantity = new TextView(this);
itemName.setText(itemTextView1);
quantity.setText(itemTextView2);
row.addView(itemName);
row.addView(quantity);
table.addView(row);
}
I expect Item Name to occupy available space, show that it matches with upper row and row that is being created.
Could really use some help with this one.
I'm trying to start with a single button at the bottom of my screen. When my counter++ button is clicked, a second button will be dynamically created above the button at the bottom of the screen. I was able to get this far, the problem is that the height of my scrollview doesn't increase when my buttons reach the top of the screen. Please see my example below.
Example
I'm assuming the scrollview only increases when items are added below the current view although if that's the case, is there no way I can create several buttons starting at the bottom going upwards?
Here my code.
XML:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:context="com.example.bbetzner.ttt.Map">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
>
<RelativeLayout
android:id="#+id/layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<Button
android:id="#+id/count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="count++"
/>
<Button
android:id="#+id/floor0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="0"
/>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
Java:
public void addfloor(){
Button myButton = new Button(this);
myButton.setText(""+floor);
margincount += 100;
RelativeLayout ll = findViewById(R.id.layout);
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
lp.addRule(RelativeLayout.ABOVE, R.id.floor0);
lp.addRule(RelativeLayout.CENTER_HORIZONTAL);
lp.bottomMargin = margincount;
ll.addView(myButton, lp);
}
I've also tried doing this in a linear layout to see if the scrollview would increase but I couldn't figure out how to stack buttons from bottom to top in a linear layout. :S
Thanks in advance, yall are awesome!
#Texas use below code using that you are achieving what you want:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:id="#+id/layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<Button
android:id="#+id/count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="count++" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:scrollbars="vertical">
<LinearLayout
android:id="#+id/lladdViews"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="bottom"
android:orientation="vertical">
<Button
android:id="#+id/floor0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="0" />
</LinearLayout>
</ScrollView>
</LinearLayout>
and here is Java File:
public class SampleActivity extends Activity {
LinearLayout lladdViews;
Button count;
int floor = 0;
private int margincount = 0;
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sample_activity);
lladdViews = (LinearLayout) findViewById(R.id.lladdViews);
count = (Button) findViewById(R.id.count);
count.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
addfloor();
}
});
}
public void addfloor() {
Button myButton = new Button(this);
myButton.setText("" + floor);
margincount += 10;
RelativeLayout ll = new RelativeLayout(this);
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
lp.addRule(RelativeLayout.ABOVE, R.id.floor0);
lp.addRule(RelativeLayout.CENTER_HORIZONTAL);
lp.bottomMargin = margincount;
ll.addView(myButton, lp);
lladdViews.addView(ll);
}
}
Here is your designing part happy coding.....
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<LinearLayout
android:id="#+id/layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
>
<Button
android:id="#+id/count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="count++"
/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
>
<LinearLayout
android:id="#+id/layout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
>
<Button
android:id="#+id/floor0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="0"
/>
<Button
android:id="#+id/floor1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="7"
/>
<Button
android:id="#+id/floor2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="6"
/>
<Button
android:id="#+id/floor3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="5"
/>
<Button
android:id="#+id/floor4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="4"
/>
<Button
android:id="#+id/floor5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="0"
/><Button
android:id="#+id/floor6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="3"
/><Button
android:id="#+id/floor7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="2"
/>
<Button
android:id="#+id/floor8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="1"
/>
<Button
android:id="#+id/floor9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="0"
/>
</LinearLayout>
</ScrollView>
</LinearLayout>
Hi i'm using eclipse for deveoping this android app. I'm inflating a layout using inflator and everything works fine.. I'm adding those inflated items one by one to another layout, so when the device's orientation is changed, all those inflated items are gone. The application seems like it has been restarted. But some values are still remaining.. Please help..
public void addNewItem() {
LayoutInflater li = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View item = li.inflate(R.layout.activity_order_items, null);
orderItemFrameView.add(item);
itemsLayout.addView(item);
setAdditionalFonts(item);
}
private void setAdditionalFonts(View view) {
TextView lblNameTak = (TextView)view.findViewById(R.id.tak_itemNo);
AutoCompleteTextView txtNameTak = (AutoCompleteTextView)view.findViewById(R.id.tak_itemName);
ImageView barScan = (ImageView)view.findViewById(R.id.barcode_scan);
TextView lblRate = (TextView)view.findViewById(R.id.tak_lblRate);
TextView lblQty = (TextView)view.findViewById(R.id.tak_lblQty);
TextView lblTotal = (TextView)view.findViewById(R.id.tak_lblTotal);
TextView rate = (TextView)view.findViewById(R.id.tak_Rate);
EditText2 qty = (EditText2)view.findViewById(R.id.tak_Qty);
TextView total = (TextView)view.findViewById(R.id.tak_Total);
qty.totTextView = total;
qty.rateTextView = rate;
qty.orderTake = this;
qty.index = orderItemFrameView.size() - 1;
qty.sqlDb = SqlDb;
qty.itemName = txtNameTak;
setupBarcodeScan(barScan);
Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/ubuntu-l.ttf");
Typeface tf2 = Typeface.createFromAsset(getAssets(), "fonts/calibri.ttf");
Typeface tf3 = Typeface.createFromAsset(getAssets(), "fonts/ubu-r.ttf");
Typeface tf4 = Typeface.createFromAsset(getAssets(), "fonts/tahoma.ttf");
lblNameTak.setTypeface(tf3);
txtNameTak.setTypeface(tf2);
lblRate.setTypeface(tf2);
lblQty.setTypeface(tf2);
lblTotal.setTypeface(tf2);
lblNameTak.setText("Item " + (qty.index + 1));
DbAdapterItem dbItem;
TextAdapterItem txtItem;
dbItem = new DbAdapterItem(this, SqlDb);
txtItem = new TextAdapterItem(dbItem, this, qty);
txtNameTak.setAdapter(txtItem);
txtNameTak.setOnItemClickListener(txtItem);
txtNameTak.requestFocus();
}
all these items created by addNewItem() are vanished...
here is the layout from which i'm inflating...
<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:paddingBottom ="22dp"
tools:context=".OrderItems" >
<FrameLayout
android:layout_width="match_parent"
android:background= "#888888"
android:layout_height="98dp" >
<TextView
android:id="#+id/tak_itemNo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="15dp"
android:layout_marginTop="2.7dp"
android:text="Item 1"
android:layout_gravity="right"
android:textColor="#DDDDDD" />
<LinearLayout
android:layout_width="match_parent"
android:layout_marginTop="22dp"
android:orientation="vertical"
android:background= "#FFFFFF"
android:layout_height="75dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<AutoCompleteTextView
android:id="#+id/tak_itemName"
android:imeOptions="actionUnspecified"
android:imeActionLabel="search"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="0dp"
android:layout_weight="1.06"
android:completionThreshold="1"
android:ems="10"
android:hint="Item Name / Barcode"
android:inputType="textCapWords"
android:singleLine="true"
android:textColorHint="#DDDDDD" />
<ImageView
android:id="#+id/barcode_scan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="7dp"
android:paddingRight="7dp"
android:paddingTop="6dp"
android:src="#android:drawable/ic_menu_camera" />
</LinearLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<FrameLayout
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_gravity="left"
>
<TextView
android:id="#+id/tak_lblRate"
android:layout_width="wrap_content"
android:layout_marginLeft="7dp"
android:layout_height="wrap_content"
android:textColor="#555555"
android:textSize="10sp"
android:text="Rate" />
<TextView
android:id="#+id/tak_Rate"
android:layout_width="match_parent"
android:layout_marginTop="12dp"
android:layout_marginRight="15dp"
android:layout_height="wrap_content"
android:gravity="right"
android:textSize="16sp"
android:text="0.00" />
</FrameLayout>
<FrameLayout
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
>
<TextView
android:id="#+id/tak_lblQty"
android:layout_width="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginRight="7dp"
android:layout_height="wrap_content"
android:textColor="#555555"
android:textSize="10sp"
android:text="Qty" />
<com.sayka.ordergadget.EditText2
android:id="#+id/tak_Qty"
android:layout_width="match_parent"
android:layout_marginBottom="-4dp"
android:layout_marginTop="4dp"
android:inputType="numberDecimal"
android:imeOptions="actionNext"
android:layout_marginLeft="12dp"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="16sp"
android:text="0.0" />
</FrameLayout>
<FrameLayout
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_gravity="right"
>
<TextView
android:id="#+id/tak_lblTotal"
android:layout_width="wrap_content"
android:layout_marginLeft="7dp"
android:layout_gravity="left"
android:layout_height="wrap_content"
android:textColor="#555555"
android:textSize="10sp"
android:text="Total" />
<TextView
android:id="#+id/tak_Total"
android:layout_width="match_parent"
android:layout_gravity="right"
android:layout_marginTop="12dp"
android:layout_marginRight="15dp"
android:layout_height="wrap_content"
android:gravity="right"
android:textSize="16sp"
android:text="0.00" />
</FrameLayout>
</FrameLayout>
</LinearLayout>
</FrameLayout>
It's normal behaviour and you are correct. the activity is recreated from scratch on rotation.
If you want something to persist. store it during onSaveInstanceState in the provided bundle.
then during onCreate check to see if the bundle is null, if it isn't, pull your data out and add the view elements again.
Alternatively you can fudge it and state in the manifest that your activity will handle orientation/configuration changes.