Android: Query to retrive data from db and populate on edittexts - android

I have a employee table in the database and have an activity where user inserts the employee details into the table
Now I have to also update the particular employee , so , I used the same xml with different buttons setting the visibility as gone and visible for update and insert buttons respectively
Now when the user clicks on update, I want to display the same xml but with the Edittexts filled with the employee details already and then can be editable
how can I do that ??
this is my xml
<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#drawable/background"
android:gravity="top" >
<TextView
android:id="#+id/TV"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginTop="20sp"
android:gravity="center_horizontal"
android:text="Employee Entry details"
android:textColor="#000000"
android:textSize="35sp"
android:textStyle="italic" />
<LinearLayout
android:id="#+id/mainll"
android:layout_width="fill_parent"
android:layout_height="650sp"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/TV"
android:layout_marginTop="10dp"
android:orientation="vertical" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50sp">
<TextView
android:id="#+id/enametext"
android:layout_width="260sp"
android:layout_height="wrap_content"
android:text="Employee Name:"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#000000"
android:textSize="30sp" />
<EditText
android:id="#+id/enameedit"
android:layout_width="340sp"
android:layout_height="wrap_content" >
<requestFocus />
</EditText>
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20sp">
<TextView
android:id="#+id/edesignationtext"
android:layout_width="260sp"
android:layout_height="wrap_content"
android:text="Employee Designation:"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#000000"
android:textSize="30sp"/>
<EditText
android:id="#+id/edesignationedit"
android:layout_width="340sp"
android:layout_height="wrap_content" >
</EditText>
</TableRow>
<TableRow
android:id="#+id/tableRow3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20sp">
<TextView
android:id="#+id/enumbertext"
android:layout_width="260sp"
android:layout_height="wrap_content"
android:text="Employee Phone Number:"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#000000"
android:textSize="30sp"/>
<EditText
android:id="#+id/enumberedit"
android:layout_width="340sp"
android:layout_height="wrap_content"
>
</EditText>
</TableRow>
<TableRow
android:id="#+id/tableRow4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20sp">
<TextView
android:id="#+id/edobtext"
android:layout_width="260sp"
android:layout_height="wrap_content"
android:text="Employee D.O.B :"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#000000"
android:textSize="30sp"/>
<EditText
android:id="#+id/edobedit"
android:layout_width="250sp"
android:layout_height="wrap_content"
/>
<Button
android:id="#+id/dateOfBirth"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Date"
android:textColor="#000000"
android:textSize="30sp"
android:background="#ffffff" />
</TableRow>
<TableRow
android:id="#+id/tableRow5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20sp">
<TextView
android:id="#+id/ebasicpaytext"
android:layout_width="260sp"
android:layout_height="wrap_content"
android:text="Employee Basic Pay :"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#000000"
android:textSize="30sp"/>
<EditText
android:id="#+id/ebasicpayedit"
android:layout_width="340sp"
android:layout_height="wrap_content"
/>
</TableRow>
<TableRow
android:id="#+id/tableRow6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20sp">
<TextView
android:id="#+id/epftext"
android:layout_width="260sp"
android:layout_height="wrap_content"
android:text="Employee PF deduction :"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#000000"
android:textSize="30sp"/>
<EditText
android:id="#+id/epfedit"
android:layout_width="340sp"
android:layout_height="wrap_content"
/>
</TableRow>
<TableRow
android:id="#+id/tableRow6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20sp">
<TextView
android:id="#+id/eotherdeductionstext"
android:layout_width="260sp"
android:layout_height="wrap_content"
android:text="Employee Other Deductions :"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#000000"
android:textSize="30sp"/>
<EditText
android:id="#+id/eotherdeductionedit"
android:layout_width="340sp"
android:layout_height="wrap_content"
/>
</TableRow>
</LinearLayout>
<TableRow
android:id="#+id/inserttablerow"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/mainll"
android:layout_marginTop="61dp"
android:visibility="visible" >
<Button
android:id="#+id/savebutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="70sp"
android:background="#ffffff"
android:text="Save"
android:textColor="#000000"
android:textSize="30sp" />
<Button
android:id="#+id/cancelbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="100sp"
android:background="#ffffff"
android:text="Cancel"
android:textColor="#000000"
android:textSize="30sp" />
<Button
android:id="#+id/addanotheremployeebutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ffffff"
android:layout_marginLeft="100sp"
android:text="Add new"
android:textColor="#000000"
android:textSize="30sp" />
</TableRow>
<TableRow
android:id="#+id/updatetablerow"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/mainll"
android:layout_marginTop="61dp"
android:visibility="gone" >
<Button
android:id="#+id/updatesavebutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="160sp"
android:background="#ffffff"
android:text="Update"
android:textColor="#000000"
android:textSize="30sp" />
<Button
android:id="#+id/updatecancelbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="100sp"
android:background="#ffffff"
android:text="Cancel"
android:textColor="#000000"
android:textSize="30sp" />
</TableRow>
and my insert and update methods from datahelper class
//inserting into employeetable
public void insertDataIntoEmployee(String name_STR, String designation_STR, String phonenumber_STR, String age_STR,
String basicpay_STR, String pfdeduction_STR, String otherdeductions_STR) {
System.out.println(" insertData start ");
cv = new ContentValues();
cv.put("ename", name_STR);
cv.put("edesignation", designation_STR);
cv.put("ephonenumber", phonenumber_STR);
cv.put("eage", age_STR);
cv.put("ebasic", basicpay_STR);
cv.put("epf", pfdeduction_STR);
cv.put("eotherdeductions", otherdeductions_STR);
this.db.insert(EMPLOYEE_TABLE_NAME, null, cv);
System.out.println(" insertData end ");
}
// updating the table
public void updateDataIntoEmployee(long rowId ,String name_STR, String designation_STR, String phonenumber_STR, String age_STR,
String basicpay_STR, String pfdeduction_STR, String otherdeductions_STR) {
System.out.println(" updateData start ");
cv = new ContentValues();
cv.put("ename", name_STR);
cv.put("edesignation", designation_STR);
cv.put("ephonenumber", phonenumber_STR);
cv.put("eage", age_STR);
cv.put("ebasic", basicpay_STR);
cv.put("epf", pfdeduction_STR);
cv.put("eotherdeductions", otherdeductions_STR);
this.db.update(EMPLOYEE_TABLE_NAME, cv, EMPLOYEE_ID + "=" + rowId, null);
System.out.println(" updateData end ");
}
and my method in class where i have to display the populated edittexts is here
public void onCreate(Bundle savedState) {
EditText editText = (EditText) findViewById(R.id.my_edittext);
String value = // Query your 'last value'.
editText.setText(value);
}
Now what can be the query which has to be passed in string value which can be retrieved and also , am I supposed to rewrite this code every time for each edit texts?
Is there anyway to avoid the redundancy?
Thank you

You can try something like
String[] mProjection = {/* All The Columns which you want to retrieve */};
Cursor cursor = this.db.query(EMPLOYEE_TABLE_NAME, mProjection, EMPLOYEE_NAME + "=?", new String[] { name_STR }, null, null, null);
This will return all the columns names in one shot and you can use whatever you wish. No need to query the db again and again.
After getting the cursor,
if (cursor != null && cursor.moveToNext()) {
// you can store all the returned columns in a custom class here and return that class object
}

Related

List view rows not getting clicked?

I am creating a ListView with list of items and trying to print some toast on clicking each row of the ListView but the toast is getting printedwhen I am clicking on the header part of the ListView but not coming when clicking on the rows of the ListView. What can be the issue. I am not able to get as to why it is not recognising the click on the rows of the ListView.
Please help me. Thanx in advance!!!
Here is my code
Main Activity.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="match_parent"
android:layout_height="match_parent"
tools:context="com.example.ankit.surya1.MainActivity">
<HorizontalScrollView
android:layout_marginTop="5dp"
android:layout_width="1500dp"
android:layout_height="match_parent">
<ListView
android:id="#+id/listview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="10dp" />
</HorizontalScrollView>
</RelativeLayout>
Main Activity.java
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ListView listView = (ListView) findViewById(R.id.listview);
ViewGroup headerView = (ViewGroup) getLayoutInflater().inflate(R.layout.header, listView, false);
listView.addHeaderView(headerView);
String[] items = getResources().getStringArray(R.array.list_items);
LstViewAdapter adapter = new LstViewAdapter(MainActivity.this, R.layout.rowlayout, items);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
/*
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle("Choose");
builder.setIcon(R.drawable.checked);
final CharSequence[] items = {"Call", "Send SMS"};
builder.setItems(items, new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int item) {
// t12.setText(items[item]);
if (items[item] == "call") {
// write the calll code here......................................
}
if (items[item] == "Send SMS") {
//write the sms code here..........................................
}
}
});
AlertDialog alert = builder.create();
alert.show();*/
switch(position)
{
case 0: {
Toast.makeText(getApplicationContext(), "hi ki", Toast.LENGTH_SHORT).show();
}
break;
case 1: {
Toast.makeText(getApplicationContext(), "hi ki", Toast.LENGTH_SHORT).show();
}
break;
case 2: {
Toast.makeText(getApplicationContext(), "hi ki", Toast.LENGTH_SHORT).show();
}
break;
}
}
});
}
}
header.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout
android:layout_width="1200dp"
android:layout_height="wrap_content"
android:background="#9E9E9E"
>
<TextView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_column="0"
android:background="#drawable/table1"
android:gravity="left"
android:padding="10sp"
android:text="Type"
android:textColor="#color/white"
android:textStyle="bold"></TextView>
<TextView
android:layout_width="100dp"
android:layout_column="1"
android:layout_height="wrap_content"
android:padding="10sp"
android:gravity="left"
android:text="Loan #"
android:textColor="#color/white"
android:textStyle="bold"
android:background="#drawable/table1"
>
</TextView>
<TextView
android:layout_width="100dp"
android:layout_column="2"
android:padding="10sp"
android:gravity="left"
android:textColor="#color/white"
android:text="Name"
android:textStyle="bold"
android:background="#drawable/table1"
android:layout_height="wrap_content"
>
</TextView>
<TextView
android:layout_width="100dp"
android:layout_column="2"
android:background="#drawable/table1"
android:gravity="left"
android:padding="10sp"
android:text="Ph No"
android:textColor="#color/white"
android:textStyle="bold"
android:layout_height="wrap_content"
></TextView>
<TextView
android:layout_height="wrap_content"
android:layout_width="100dp"
android:layout_column="4"
android:padding="10sp"
android:gravity="left"
android:text="Address"
android:textColor="#color/white"
android:textStyle="bold"
android:background="#drawable/table1"
>
</TextView>
<TextView
android:layout_height="wrap_content"
android:layout_width="100dp"
android:layout_column="5"
android:padding="10sp"
android:gravity="left"
android:textColor="#color/white"
android:text="Area"
android:textStyle="bold"
android:background="#drawable/table1"
>
</TextView>
<TextView
android:layout_height="wrap_content"
android:layout_width="100dp"
android:layout_column="6"
android:padding="10sp"
android:gravity="left"
android:textColor="#color/white"
android:text="Amount"
android:textStyle="bold"
android:background="#drawable/table1"
>
</TextView>
<TextView
android:layout_height="wrap_content"
android:layout_width="100dp"
android:layout_column="7"
android:padding="10sp"
android:gravity="left"
android:textColor="#color/white"
android:text="ROI"
android:textStyle="bold"
android:background="#drawable/table1"
>
</TextView>
<TextView
android:layout_height="wrap_content"
android:layout_width="100dp"
android:layout_column="8"
android:padding="10sp"
android:textColor="#color/white"
android:gravity="left"
android:text="Interest"
android:textStyle="bold"
android:background="#drawable/table1"
>
</TextView>
<TextView
android:layout_height="wrap_content"
android:layout_width="100dp"
android:layout_column="9"
android:padding="10sp"
android:gravity="left"
android:textColor="#color/white"
android:text="Total"
android:textStyle="bold"
android:background="#drawable/table1"
>
</TextView>
<TextView
android:layout_height="wrap_content"
android:layout_width="100dp"
android:layout_column="10"
android:padding="10sp"
android:gravity="left"
android:text="DaysLeft"
android:textColor="#color/white"
android:textStyle="bold"
android:background="#drawable/table1"
>
</TextView>
<TextView
android:layout_height="wrap_content"
android:layout_width="100dp"
android:layout_column="11"
android:padding="10sp"
android:gravity="left"
android:text="SMS Count"
android:textColor="#color/white"
android:textStyle="bold"
android:background="#drawable/table1"
>
</TextView>
</LinearLayout>
</LinearLayout>
rowlayout.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout
android:layout_width="1200dp"
android:layout_height="wrap_content"
android:background="#9E9E9E"
>
<TextView
android:id="#+id/t1"
android:layout_width="100dp"
android:layout_column="0"
android:layout_height="match_parent"
android:gravity="left"
android:padding="10sp"
android:textColor="#000000"
android:inputType="text"
>
</TextView>
<TextView
android:id="#+id/t2"
android:layout_width="100dp"
android:layout_column="1"
android:layout_height="match_parent"
android:padding="10sp"
android:gravity="left"
android:inputType="number"
android:textColor="#000000"
>
</TextView>
<TextView
android:id="#+id/t3"
android:layout_height="match_parent"
android:layout_column="2"
android:padding="10sp"
android:gravity="left"
android:textColor="#000000"
android:inputType="textPersonName"
android:layout_width="100dp"
>
</TextView>
<TextView
android:layout_height="match_parent"
android:id="#+id/t4"
android:layout_width="100dp"
android:layout_column="3"
android:padding="10sp"
android:gravity="left"
android:textColor="#000000"
android:inputType="phone"
>
</TextView>
<TextView
android:layout_height="match_parent"
android:id="#+id/t5"
android:layout_width="100dp"
android:layout_column="4"
android:padding="10sp"
android:gravity="left"
android:textColor="#000000"
android:inputType="text"
>
</TextView>
<TextView
android:layout_height="match_parent"
android:id="#+id/t6"
android:layout_width="100dp"
android:layout_column="5"
android:padding="10sp"
android:gravity="left"
android:textColor="#000000"
android:inputType="text"
>
</TextView>
<TextView
android:layout_height="match_parent"
android:id="#+id/t7"
android:layout_width="100dp"
android:layout_column="6"
android:padding="10sp"
android:gravity="left"
android:textColor="#000000"
android:inputType="number"
>
</TextView>
<TextView
android:layout_height="match_parent"
android:id="#+id/t8"
android:layout_width="100dp"
android:layout_column="7"
android:padding="10sp"
android:gravity="left"
android:textColor="#000000"
android:inputType="number"
>
</TextView>
<TextView
android:layout_height="match_parent"
android:id="#+id/t9"
android:layout_width="100dp"
android:layout_column="8"
android:padding="10sp"
android:textColor="#000000"
android:gravity="left"
android:inputType="number"
>
</TextView>
<TextView
android:layout_height="match_parent"
android:id="#+id/t10"
android:layout_width="100dp"
android:layout_column="9"
android:padding="10sp"
android:gravity="left"
android:textColor="#000000"
android:inputType="number"
>
</TextView>
<TextView
android:layout_height="match_parent"
android:id="#+id/t11"
android:layout_width="100dp"
android:layout_column="10"
android:padding="10sp"
android:gravity="left"
android:textColor="#000000"
android:inputType="number"
>
</TextView>
<TextView
android:layout_height="match_parent"
android:id="#+id/t12"
android:layout_width="100dp"
android:layout_column="11"
android:padding="10sp"
android:gravity="left"
android:textColor="#000000"
android:inputType="number"
>
</TextView>
</LinearLayout>
</LinearLayout>
strings.xml
<string-array name="list_items">
<item>Gold__4__Jahn Ibrahim__9556551456__LB Nagar__Hyd__95220__6__2920__22920__-26__0__</item>
<item>Gold__3__Amit Kumar__9556325566__KpHB __Hyd__20000__3__2920__22580__-4__0__</item>
<item>Gold__7__Mohan__9556458745__Hitecy__Hyd__95226__3__2920__23570__-5__0__</item>
<item>Gold__8__Ravi__9556551456__LB Nagar__Hyd__95220__6__2920__278750__-26__0__</item>
<item>Gold__3__Sunil__9556325566__KpHB __Hyd__20000__3__2920__27540__-4__0__</item>
<item>Gold__9__Amit__9556458745__Hitecy__Hyd__95226__3__2920__27780__-5__0__</item>
<item>Gold__5__Mohan__9556551456__LB Nagar__Hyd__95220__6__2920__278740__-26__0__</item>
<item>Gold__3__Amit__9556325566__KpHB __Hyd__20000__3__2920__22920__-4__0__</item>
<item>Gold__7__Jain__9556458745__Hitecy__Hyd__95226__3__2920__22920__-5__0__</item>
</string-array>

output of my json response is displaying last item in the database

I am trying to display the content of my database in a tablelayout, I have fetch the data from the database, and set it to be displayed in my android app, but when the data displays, it overwrite the data fetch earlier and only show the last item.
this is an except form my code where I think I got the code wrong
#Override
protected void onPostExecute(String result) {
/* TextView textView= (TextView)findViewById(R.id.textview);
textView.setText(result);*/
json_string = result;
try {
jsonObject = new JSONObject(json_string);
jsonArray = jsonObject.getJSONArray("server_response");
int count = 0;
String id, inv_id, refnumber, description, details, qty, unit_price, amount;
Double subTotal = 00.00;
int sn = 1;
Double dAmount;
while (count < jsonArray.length()) {
JSONObject JO = jsonArray.getJSONObject(count);
description = JO.getString("description");
qty = JO.getString("qty");
unit_price = JO.getString("unit_price");
amount = JO.getString("amount");
txtDescription.setText(description);
txtQty.setText(qty);
txtUnit_price.setText(unit_price);
txtAmount.setText(amount);
txtsn.setText(String.valueOf(sn));
count++;
sn++;
try {
subTotal = subTotal + Double.valueOf(amount);
// dAmount = Double.valueOf(amount);
} catch (NumberFormatException e) {
subTotal = 00.00;
}
}
txtSubTotal.setText(String.valueOf(subTotal));
double VAT = 0.05*(subTotal);
txtVat.setText(String.valueOf(VAT));
Double Total = VAT + subTotal;
txtTotal.setText(String.valueOf(Total));
} catch (JSONException e) {
e.printStackTrace();
}
}
my XML layout is as follows
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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"
tools:context="ng.proartisan.invoiceapp.MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TableRow>
<TextView
android:text="S/N"
android:background="#drawable/cellborder"
android:layout_weight="1"
android:gravity="center"
android:padding="5dp"
android:textStyle="bold"
/>
<TextView
android:text="Description"
android:background="#drawable/cellborder"
android:padding="5dp"
android:layout_weight="4"
android:gravity="center"
android:textStyle="bold"
/>
<TextView
android:text="QTY"
android:background="#drawable/cellborder"
android:layout_weight="1"
android:padding="5dp"
android:gravity="center"
android:textStyle="bold"
/>
<TextView
android:text="Unit Price"
android:background="#drawable/cellborder"
android:layout_weight="2"
android:padding="5dp"
android:gravity="center"
android:textStyle="bold"
/>
<TextView
android:text="Amount"
android:background="#drawable/cellborder"
android:layout_weight="2"
android:padding="5dp"
android:gravity="center"
android:textStyle="bold"
/>
</TableRow>
<TableRow>
<TextView
android:id="#+id/sn"
android:text="S/N"
android:background="#drawable/cellborder"
android:layout_weight="1"
android:gravity="center"
android:padding="5dp"
/>
<TextView
android:id="#+id/description"
android:text="Description"
android:background="#drawable/cellborder"
android:padding="5dp"
android:layout_weight="4"
android:gravity="center"
/>
<TextView
android:id="#+id/qty"
android:text="QTY"
android:background="#drawable/cellborder"
android:layout_weight="1"
android:padding="5dp"
android:gravity="center"
/>
<TextView
android:id="#+id/unit_price"
android:text="Unit Price"
android:background="#drawable/cellborder"
android:layout_weight="2"
android:padding="5dp"
android:gravity="center"
/>
<TextView
android:id="#+id/amount"
android:text="Amount"
android:background="#drawable/cellborder"
android:layout_weight="2"
android:padding="5dp"
android:gravity="center"
/>
</TableRow>
<TableRow>
<TextView
android:background="#drawable/cellborder"
android:layout_weight="1"
android:gravity="center"
android:padding="5dp"
/>
<TextView
android:text="SubTotal"
android:background="#drawable/cellborder"
android:padding="5dp"
android:layout_weight="4"
android:gravity="center"
/>
<TextView
android:background="#drawable/cellborder"
android:layout_weight="1"
android:padding="5dp"
android:gravity="center"
/>
<TextView
android:background="#drawable/cellborder"
android:layout_weight="2"
android:padding="5dp"
android:gravity="center"
/>
<TextView
android:id="#+id/subtotal"
android:text=""
android:background="#drawable/cellborder"
android:layout_weight="2"
android:padding="5dp"
android:gravity="center"
/>
</TableRow>
<TableRow>
<TextView
android:background="#drawable/cellborder"
android:layout_weight="1"
android:gravity="center"
android:padding="5dp"
/>
<TextView
android:text="VAT"
android:background="#drawable/cellborder"
android:padding="5dp"
android:layout_weight="4"
android:gravity="center"
/>
<TextView
android:background="#drawable/cellborder"
android:layout_weight="1"
android:padding="5dp"
android:gravity="center"
/>
<TextView
android:background="#drawable/cellborder"
android:layout_weight="2"
android:padding="5dp"
android:gravity="center"
/>
<TextView
android:id="#+id/vat"
android:text=""
android:background="#drawable/cellborder"
android:layout_weight="2"
android:padding="5dp"
android:gravity="center"
/>
</TableRow>
<TableRow>
<TextView
android:background="#drawable/cellborder"
android:layout_weight="1"
android:gravity="center"
android:padding="5dp"
/>
<TextView
android:text="Total"
android:background="#drawable/cellborder"
android:padding="5dp"
android:layout_weight="4"
android:gravity="center"
/>
<TextView
android:background="#drawable/cellborder"
android:layout_weight="1"
android:padding="5dp"
android:gravity="center"
/>
<TextView
android:background="#drawable/cellborder"
android:layout_weight="2"
android:padding="5dp"
android:gravity="center"
/>
<TextView
android:id="#+id/total"
android:text=""
android:background="#drawable/cellborder"
android:layout_weight="2"
android:padding="5dp"
android:gravity="center"
/>
</TableRow>
</TableLayout>
</LinearLayout>
</ScrollView>
please help
You are setting the data into same view in loop, other way to solve your problem like create a new layout and add into your layout example: XML file layout_item_description.xml
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TableRow>
<TextView
android:id="#+id/tv_sn"
android:layout_weight="1"
android:gravity="center"
android:padding="5dp"
android:text="S/N"
android:textStyle="bold"
/>
<TextView
android:id="#+id/tv_description"
android:layout_weight="4"
android:gravity="center"
android:padding="5dp"
android:text="Description"
android:textStyle="bold" />
<TextView
android:id="#+id/tv_qty"
android:layout_weight="1"
android:gravity="center"
android:padding="5dp"
android:text="QTY"
android:textStyle="bold" />
<TextView
android:id="#+id/tv_unit_price"
android:layout_weight="2"
android:gravity="center"
android:padding="5dp"
android:text="Unit Price"
android:textStyle="bold" />
<TextView
android:id="#+id/tv_amount"
android:layout_weight="2"
android:gravity="center"
android:padding="5dp"
android:text="Amount"
android:textStyle="bold" />
</TableRow>
</TableLayout>
add this item view to your layout. Your XML Layout file:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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"
tools:context="ng.proartisan.invoiceapp.MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TableRow>
<TextView
android:text="S/N"
android:background="#drawable/cellborder"
android:layout_weight="1"
android:gravity="center"
android:padding="5dp"
android:textStyle="bold"
/>
<TextView
android:text="Description"
android:background="#drawable/cellborder"
android:padding="5dp"
android:layout_weight="4"
android:gravity="center"
android:textStyle="bold"
/>
<TextView
android:text="QTY"
android:background="#drawable/cellborder"
android:layout_weight="1"
android:padding="5dp"
android:gravity="center"
android:textStyle="bold"
/>
<TextView
android:text="Unit Price"
android:background="#drawable/cellborder"
android:layout_weight="2"
android:padding="5dp"
android:gravity="center"
android:textStyle="bold"
/>
<TextView
android:text="Amount"
android:background="#drawable/cellborder"
android:layout_weight="2"
android:padding="5dp"
android:gravity="center"
android:textStyle="bold"
/>
</TableRow>
</TableLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="#+id/ll_data_description"/>
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TableRow>
<TextView
android:background="#drawable/cellborder"
android:layout_weight="1"
android:gravity="center"
android:padding="5dp"
/>
<TextView
android:text="SubTotal"
android:background="#drawable/cellborder"
android:padding="5dp"
android:layout_weight="4"
android:gravity="center"
/>
<TextView
android:background="#drawable/cellborder"
android:layout_weight="1"
android:padding="5dp"
android:gravity="center"
/>
<TextView
android:background="#drawable/cellborder"
android:layout_weight="2"
android:padding="5dp"
android:gravity="center"
/>
<TextView
android:id="#+id/subtotal"
android:text=""
android:background="#drawable/cellborder"
android:layout_weight="2"
android:padding="5dp"
android:gravity="center"
/>
</TableRow>
<TableRow>
<TextView
android:background="#drawable/cellborder"
android:layout_weight="1"
android:gravity="center"
android:padding="5dp"
/>
<TextView
android:text="VAT"
android:background="#drawable/cellborder"
android:padding="5dp"
android:layout_weight="4"
android:gravity="center"
/>
<TextView
android:background="#drawable/cellborder"
android:layout_weight="1"
android:padding="5dp"
android:gravity="center"
/>
<TextView
android:background="#drawable/cellborder"
android:layout_weight="2"
android:padding="5dp"
android:gravity="center"
/>
<TextView
android:id="#+id/vat"
android:text=""
android:background="#drawable/cellborder"
android:layout_weight="2"
android:padding="5dp"
android:gravity="center"
/>
</TableRow>
<TableRow>
<TextView
android:background="#drawable/cellborder"
android:layout_weight="1"
android:gravity="center"
android:padding="5dp"
/>
<TextView
android:text="Total"
android:background="#drawable/cellborder"
android:padding="5dp"
android:layout_weight="4"
android:gravity="center"
/>
<TextView
android:background="#drawable/cellborder"
android:layout_weight="1"
android:padding="5dp"
android:gravity="center"
/>
<TextView
android:background="#drawable/cellborder"
android:layout_weight="2"
android:padding="5dp"
android:gravity="center"
/>
<TextView
android:id="#+id/total"
android:text=""
android:background="#drawable/cellborder"
android:layout_weight="2"
android:padding="5dp"
android:gravity="center"
/>
</TableRow>
</TableLayout>
</LinearLayout>
</ScrollView>
Add LinearLayout ll_data_description = (LinearLayout)findViewById(R.id.ll_data_description);
#Override
protected void onPostExecute(String result) {
/* TextView textView= (TextView)findViewById(R.id.textview);
textView.setText(result);*/
json_string = result;
try {
jsonObject = new JSONObject(json_string);
jsonArray = jsonObject.getJSONArray("server_response");
int count = 0;
String id, inv_id, refnumber, description, details, qty, unit_price, amount;
Double subTotal = 00.00;
int sn = 1;
Double dAmount;
while (count < jsonArray.length()) {
JSONObject JO = jsonArray.getJSONObject(count);
View layout_item_description = getLayoutInflater().inflate(R.layout.layout_item_description, null);
((TextView) layout_item_description.findViewById(R.id.tv_sn)).setText(sn+"");
description = JO.getString("description");
qty = JO.getString("qty");
unit_price = JO.getString("unit_price");
amount = JO.getString("amount");
((TextView) layout_item_description.findViewById(R.id.tv_description)).setText(sn+"");
((TextView) layout_item_description.findViewById(R.id.tv_qty)).setText(sn+"");
((TextView) layout_item_description.findViewById(R.id.tv_unit_price)).setText(sn+"");
((TextView) layout_item_description.findViewById(R.id.tv_amount)).setText(sn+"");
count++;
sn++;
ll_data_description.addView(layout_item_description);
try {
subTotal = subTotal + Double.valueOf(amount);
// dAmount = Double.valueOf(amount);
} catch (NumberFormatException e) {
subTotal = 00.00;
}
}
txtSubTotal.setText(String.valueOf(subTotal));
double VAT = 0.05*(subTotal);
txtVat.setText(String.valueOf(VAT));
Double Total = VAT + subTotal;
txtTotal.setText(String.valueOf(Total));
} catch (JSONException e) {
e.printStackTrace();
}
}

androit text view Mysql

Hello I am developing an application android, I have a problem with a text view that retrieves the data via web service, the data retrieve appears but infringe on the other text view of the page, Here is my code from my xml page:
<?xml version="1.0" encoding="utf-8"?>
<TextView
android:id="#+id/tvd"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="Détail de l'établissement"
android:textSize="20dp"
android:textStyle="bold"/>
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="42dp"
android:text="Libelle :"
android:textSize="20dp"
android:textStyle="bold"
android:layout_below="#+id/tvd"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="64dp"
android:text="Code postal :"
android:textSize="20dp"
android:textStyle="bold"
android:layout_below="#+id/textView3"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="64dp"
android:text="Ville :"
android:textSize="20dp"
android:textStyle="bold"
android:layout_below="#+id/textView4"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:id="#+id/tvl"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/textView3"
android:layout_alignParentEnd="true"
android:hint="libelle"
android:textSize="20dp"
/>
<TextView
android:id="#+id/tvcp"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/tvl"
android:layout_alignStart="#+id/tvl"
android:layout_alignTop="#+id/textView4"
android:hint="Code postal"
android:textSize="20dp" />
<TextView
android:id="#+id/tvv"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/tvcp"
android:layout_alignStart="#+id/tvcp"
android:layout_alignTop="#+id/textView5"
android:hint="Ville"
android:textSize="20dp" />
<Button
android:id="#+id/btnMa"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="Matériel numérique associé"
android:textSize="20dp"
android:textStyle="bold|italic"
/>
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textSize="20dp"
android:textStyle="bold"
android:layout_below="#+id/textView5"
android:layout_marginTop="39dp"
android:text="Présentation" />
<TextView
android:id="#+id/tvp"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/textView"
android:layout_alignLeft="#+id/tvv"
android:layout_alignStart="#+id/tvv"
android:hint="Presentation"
android:textSize="20dp" />
Then my code that says or go data :
public class DetailEtab extends Activity {
private TextView tv;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.etabdetail);
tv = (TextView) findViewById(R.id.tvl);
tv.setText(search_ville.etabSELECT.getLibelle());
tv = (TextView) findViewById(R.id.tvcp);
tv.setText(search_ville.etabSELECT.getCp());
tv = (TextView) findViewById(R.id.tvv);
tv.setText(search_ville.etabSELECT.getVille());
tv = (TextView) findViewById(R.id.tvp);
tv.setText(search_ville.etabSELECT.getPresentation());
Button btnSa = (Button) findViewById(R.id.btnMa);
btnSa.setOnClickListener(new Button.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(DetailEtab.this, MaterielAssocie.class);
startActivity(intent);
Log.i("ETAB", "servcies associes");
Toast toast = Toast.makeText(getApplicationContext(), "services associes", Toast.LENGTH_SHORT);
toast.show();
}
});
}
}
If anyone can tell me why it does that thanks
[screenshot][1] [1]: https://i.stack.imgur.com/ImHxk.png
You have problems with your layouts. I recommend you to wrap every line into separate LinearLayout and then use LinearLayout to wrap all new LinearLayouts. Also due to long text it's better to wrap parent LinearLayout into Scroll.
NOTE: This is just example that was written inside text box that simply shows main idea and may contain mistakes
Something like this:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/tvd"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Détail de l'établissement"
android:textSize="20dp"
android:textStyle="bold"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="42dp"
android:text="Libelle :"
android:textSize="20dp"
android:textStyle="bold"
/>
<TextView
android:id="#+id/tvl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="libelle"
android:textSize="20dp"
/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="64dp"
android:text="Code postal :"
android:textSize="20dp"
android:textStyle="bold" />
<TextView
android:id="#+id/tvcp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Code postal"
android:textSize="20dp" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="64dp"
android:text="Ville :"
android:textSize="20dp"
android:textStyle="bold" />
<TextView
android:id="#+id/tvv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Ville"
android:textSize="20dp" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp"
android:textStyle="bold"
android:layout_marginTop="39dp"
android:text="Présentation" />
<TextView
android:id="#+id/tvp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Presentation"
android:textSize="20dp" />
</LinearLayout>
<Button
android:id="#+id/btnMa"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Matériel numérique associé"
android:textSize="20dp"
android:textStyle="bold|italic"
/>
</LinearLayout>
</ScrollView>
You are assigning tv to multiple different TextViews and then you are assigning multiple values to the last TextView you assign it to.
public class DetailEtab extends Activity {
private TextView tv,tv1,tv2,tv3;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.etabdetail);
tv = (TextView) findViewById(R.id.tvl);
tv.setText(search_ville.etabSELECT.getLibelle());
tv1 = (TextView) findViewById(R.id.tvcp);
tv1.setText(search_ville.etabSELECT.getCp());
tv2 = (TextView) findViewById(R.id.tvv);
tv2.setText(search_ville.etabSELECT.getVille());
tv3 = (TextView) findViewById(R.id.tvp);
tv3.setText(search_ville.etabSELECT.getPresentation());
Button btnSa = (Button) findViewById(R.id.btnMa);
btnSa.setOnClickListener(new Button.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(DetailEtab.this, MaterielAssocie.class);
startActivity(intent);
Log.i("ETAB", "servcies associes");
Toast toast = Toast.makeText(getApplicationContext(), "services associes", Toast.LENGTH_SHORT);
toast.show();
}
});
}
}
Try this layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView
android:id="#+id/tvd"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="Détail de l'établissement"
android:textSize="20dp"
android:textStyle="bold"/>
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/tvd"
android:layout_marginTop="42dp"
android:text="Libelle :"
android:textSize="20dp"
android:textStyle="bold"/>
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/textView3"
android:layout_marginTop="64dp"
android:text="Code postal :"
android:textSize="20dp"
android:textStyle="bold"/>
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/textView4"
android:layout_marginTop="64dp"
android:text="Ville :"
android:textSize="20dp"
android:textStyle="bold"/>
<TextView
android:id="#+id/tvl"
android:layout_width="200dp"
android:layout_height="80dp"
android:layout_alignParentEnd="true"
android:text="hfdgsjfhgadsjfgajsdfhgggdsjfgsdjafhgjsdafhgjdhfgjsdhgfjdshfgjdshfgjhdgfjdshgfjhdgfjsdhgafjahgsdfjdshgfjhdsagfjhdsgafjhsdagfjhdsgafjhsadgfjfdgjshfgjhfgjhsdgfhsgdfjhdsgfjhgdsjfhgsdjfhgsdjfhgsdjfhgsdjfhgsdjfhgsdjhfgjsdhgfjsdhgfjsdhfgjsdhfgjdsfhgjsdhgfjdshgfjsdhgfjhsgdfjhsdgjfhdgfjhgdsf"
android:layout_alignTop="#+id/textView3"
android:hint="libelle"
android:textSize="20dp"
/>
<TextView
android:id="#+id/tvcp"
android:layout_width="200dp"
android:layout_height="80dp"
android:layout_alignLeft="#+id/tvl"
android:layout_alignStart="#+id/tvl"
android:layout_alignTop="#+id/textView4"
android:hint="Code postal"
android:text="hfdgsjfhgadsjfgajsdfhgggdsjfgsdjafhgjsdafhgjdhfgjsdhgfjdshfgjdshfgjhdgfjdshgfjhdgfjsdhgafjahgsdfjdshgfjhdsagfjhdsgafjhsdagfjhdsgafjhsadgfjfdgjshfgjhfgjhsdgfhsgdfjhdsgfjhgdsjfhgsdjfhgsdjfhgsdjfhgsdjfhgsdjfhgsdjhfgjsdhgfjsdhgfjsdhfgjsdhfgjdsfhgjsdhgfjdshgfjsdhgfjhsgdfjhsdgjfhdgfjhgdsf"
android:textSize="20dp"/>
<TextView
android:id="#+id/tvv"
android:layout_width="200dp"
android:layout_height="80dp"
android:layout_alignLeft="#+id/tvcp"
android:layout_alignStart="#+id/tvcp"
android:layout_alignTop="#+id/textView5"
android:text="hfdgsjfhgadsjfgajsdfhgggdsjfgsdjafhgjsdafhgjdhfgjsdhgfjdshfgjdshfgjhdgfjdshgfjhdgfjsdhgafjahgsdfjdshgfjhdsagfjhdsgafjhsdagfjhdsgafjhsadgfjfdgjshfgjhfgjhsdgfhsgdfjhdsgfjhgdsjfhgsdjfhgsdjfhgsdjfhgsdjfhgsdjfhgsdjhfgjsdhgfjsdhgfjsdhfgjsdhfgjdsfhgjsdhgfjdshgfjsdhgfjhsgdfjhsdgjfhdgfjhgdsf"
android:hint="Ville"
android:textSize="20dp"/>
<Button
android:id="#+id/btnMa"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="Matériel numérique associé"
android:textSize="20dp"
android:textStyle="bold|italic"
/>
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/textView5"
android:layout_marginTop="39dp"
android:text="Présentation"
android:textSize="20dp"
android:textStyle="bold"/>
<TextView
android:id="#+id/tvp"
android:layout_width="200dp"
android:layout_height="80dp"
android:layout_below="#+id/tvv"
android:layout_toRightOf="#id/textView"
android:layout_alignLeft="#+id/tvv"
android:layout_alignStart="#+id/tvv"
android:text="hfdgsjfhgadsjfgajsdfhgggdsjfgsdjafhgjsdafhgjdhfgjsdhgfjdshfgjdshfgjhdgfjdshgfjhdgfjsdhgafjahgsdfjdshgfjhdsagfjhdsgafjhsdagfjhdsgafjhsadgfjfdgjshfgjhfgjhsdgfhsgdfjhdsgfjhgdsjfhgsdjfhgsdjfhgsdjfhgsdjfhgsdjfhgsdjhfgjsdhgfjsdhgfjsdhfgjsdhfgjdsfhgjsdhgfjdshgfjsdhgfjhsgdfjhsdgjfhdgfjhgdsf"
android:hint="Presentation"
android:textSize="20dp"/>
</RelativeLayout>

Passing a object from my activity to my fragment

I have been trying to resolve this issue for a while now have tried to follow a few examples on here but i seem to be missing something. this is the main post i've been looking at Passing an Object from an Activity to a Fragment
UPDATE: error message i get
1900-1900/com.chris.cv10aajproject E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.chris.cv10aajproject, PID: 1900
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.chris.cv10aajproject/com.chris.cv10aajproject.editProperty}: android.view.InflateException: Binary XML file line #121: Error inflating class fragment
UPDATE 2
code to activity Axml
<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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context="com.chris.cv10aajproject.editProperty">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="address"
android:id="#+id/tvAddress"
android:ems="10"
android:layout_below="#+id/textView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TOWN"
android:id="#+id/tvTown"
android:ems="10"
android:layout_below="#+id/tvAddress"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textAppearance="?android:attr/textAppearanceMedium"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="County"
android:ems="10"
android:id="#+id/tvCounty"
android:layout_below="#+id/tvTown"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Post code"
android:id="#+id/tvPostCode"
android:ems="10"
android:layout_below="#+id/tvCounty"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Asking Price"
android:id="#+id/tvAskingPrice"
android:layout_below="#+id/tvPostCode"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Property Summary"
android:textStyle="bold"
android:id="#+id/textView"
android:layout_alignParentTop="true"
android:layout_alignRight="#+id/tvAddress"
android:layout_alignEnd="#+id/tvAddress" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Current Offer"
android:id="#+id/tvCurrentOffer"
android:layout_below="#+id/tvAskingPrice"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="DoneUpValue"
android:id="#+id/textView3"
android:layout_below="#+id/tvCurrentOffer"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Notes"
android:id="#+id/tvNotes"
android:minHeight="200px"
android:background="#276bffd0"
android:scrollbars = "vertical"
android:layout_below="#+id/textView3"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
android:layout_width="match_parent"
android:layout_height="match_parent" >
<fragment
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/tvNotes"
android:layout_alignEnd="#+id/tvNotes"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="#+id/fragBTL"
class="com.chris.cv10aajproject.BtlFragment"
android:layout_below="#+id/tvNotes"
android:layout_alignBottom="#+id/fragFlip" />
<fragment
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/tvNotes"
android:layout_alignRight="#+id/tvNotes"
android:layout_alignEnd="#+id/tvNotes"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="#+id/fragFlip"
class="com.chris.cv10aajproject.FlipFragment"
android:layout_above="#+id/toggleFlipBtl" />
<ToggleButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textOff="Change to Flip"
android:textOn="Change to BTL"
android:id="#+id/toggleFlipBtl"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:checked="false"
android:layout_alignParentBottom="true"
android:layout_toRightOf="#+id/tvAskingPrice"
android:layout_toEndOf="#+id/tvAskingPrice" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="#+id/firstLine"
android:layout_below="#+id/textView"
android:layout_toRightOf="#+id/textView3"
android:layout_toEndOf="#+id/textView3"
android:layout_marginLeft="40dp"
android:layout_marginStart="40dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Schedule"
android:id="#+id/btnSchedule"
android:onClick="GoToSchedule"
android:layout_below="#+id/fragBTL"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Calc Refurb"
android:id="#+id/btnCalcRefurb"
android:onClick="GoToRefurb"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="#+id/town23"
android:layout_below="#+id/firstLine"
android:layout_alignLeft="#+id/firstLine"
android:layout_alignStart="#+id/firstLine"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="#+id/county"
android:layout_below="#+id/town23"
android:layout_alignLeft="#+id/town23"
android:layout_alignStart="#+id/town23" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="#+id/postCode123"
android:layout_below="#+id/county"
android:layout_alignLeft="#+id/county"
android:layout_alignStart="#+id/county" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="#+id/currentOffer123"
android:layout_below="#+id/askingPrice123"
android:layout_alignLeft="#+id/askingPrice123"
android:layout_alignStart="#+id/askingPrice123" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="#+id/askingPrice123"
android:layout_below="#+id/postCode123"
android:layout_alignLeft="#+id/postCode123"
android:layout_alignStart="#+id/postCode123" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="#+id/doneUpValue123"
android:layout_below="#+id/currentOffer123"
android:layout_alignLeft="#+id/currentOffer123"
android:layout_alignStart="#+id/currentOffer123" />
Code for fragmentxml
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<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"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Flip Strategy"
android:id="#+id/textView21"
android:textStyle="bold"
android:textSize="20sp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Maxium Offer"
android:id="#+id/textView22"
android:textSize="15sp"
android:layout_below="#+id/textView21"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:hint=" Max Offer "
android:textSize="15sp"
android:id="#+id/MaxOfferFlip"
android:layout_below="#+id/textView21"
android:layout_centerHorizontal="true"
android:background="#47ff4620" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Buyer Incentive"
android:id="#+id/textView23"
android:textSize="15sp"
android:layout_below="#+id/textView22"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="4"
android:id="#+id/IncentivePer"
android:hint="Percent"
android:textSize="15sp"
android:layout_below="#+id/MaxOfferFlip"
android:layout_alignLeft="#+id/MaxOfferFlip"
android:layout_alignStart="#+id/MaxOfferFlip"
android:background="#3409f6ff" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:hint=" Incentive "
android:textSize="15sp"
android:id="#+id/textIncentive"
android:background="#47ff4620"
android:layout_below="#+id/MaxOfferFlip"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="23dp"
android:layout_marginEnd="23dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Refurb Cost"
android:textSize="15sp"
android:id="#+id/textView24"
android:layout_below="#+id/textView23"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:hint=" Refurb "
android:textSize="15sp"
android:id="#+id/refurb"
android:background="#47ff4620"
android:layout_below="#+id/IncentivePer"
android:layout_alignRight="#+id/MaxOfferFlip"
android:layout_alignEnd="#+id/MaxOfferFlip" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Holding Time cost"
android:textSize="15sp"
android:id="#+id/textView25"
android:layout_below="#+id/textView24"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:hint=" Time "
android:textSize="15sp"
android:id="#+id/holdingTime"
android:background="#47ff4620"
android:layout_below="#+id/refurb"
android:layout_alignRight="#+id/refurb"
android:layout_alignEnd="#+id/refurb" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Profit required"
android:textSize="15sp"
android:id="#+id/textView26"
android:layout_below="#+id/textView25"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="4"
android:id="#+id/profit"
android:hint="Profit"
android:textSize="15sp"
android:background="#3409f6ff"
android:layout_below="#+id/holdingTime"
android:layout_alignLeft="#+id/IncentivePer"
android:layout_alignStart="#+id/IncentivePer" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Buyiing Selling Fee"
android:id="#+id/textView27"
android:textSize="15sp"
android:layout_below="#+id/textView26"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="4"
android:id="#+id/buySellFee"
android:hint="Fee"
android:textSize="15sp"
android:background="#3409f6ff"
android:layout_below="#+id/profit"
android:layout_alignLeft="#+id/profit"
android:layout_alignStart="#+id/profit" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Monthly Mortage Cost"
android:id="#+id/textView7"
android:textSize="15sp"
android:layout_below="#+id/textView27"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:hint=" Mortage Cost "
android:textSize="15sp"
android:id="#+id/MonthMortFlip"
android:background="#47ff4620"
android:layout_alignParentBottom="true"
android:layout_alignLeft="#+id/holdingTime"
android:layout_alignStart="#+id/holdingTime" />
Fragment javaClass
public static FlipFragment newInstance(Property property ){
FlipFragment fragment = new FlipFragment();
Bundle bundle = new Bundle();
bundle.putParcelable(PROPERTY_KEY,property);
fragment.setArguments(bundle);
return fragment ;
}
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_flip,container,false);
mProperty =(Property) getArguments().getParcelable(PROPERTY_KEY);
refurbCost = (TextView) getView().findViewById(R.id.refurb);
String refurbCost2 =" " + mProperty.getRefurbCost();
refurbCost.setText(refurbCost2);
// return view;
// mProperty = editActivity.getProperty();
//if (getActivity().getIntent().getExtras() != null) {
// mProperty = getActivity().getIntent().getParcelableExtra(editProperty.PAR_KEY3);
//}
return view;
}
#Override
public void onAttach(Activity myActivity) {
super.onAttach(myActivity);
this.editActivity = (editProperty) myActivity;
}
}
i have a activity A that has two fragments one is hidden and one is displayed depending on a toggle button.
i have a custom object that is passed to my activity A using parcelable. from another activity B. i want to pass this object to both fragments from activity A the user will input some data on the fragments which will call methods in the object class, then once this is done i want to pass the object back.
my application keeps crashing when i try to open activity A ( this has only started to happen after i've tried to pass the object to the fragments if i comment it out it opens fine)
This is the code i added to my setupView method in activity A
android.support.v4.app.FragmentTransaction ft =
getSupportFragmentManager().beginTransaction();
Fragment fragment = FlipFragment.newInstance(mProperty);
ft.replace(R.id.flip_fragment,fragment);
ft.commit();
this is the code i have in my fragment java class
public static FlipFragment newInstance(Property property ){
FlipFragment fragment = new FlipFragment();
Bundle bundle = new Bundle();
bundle.putParcelable(PROPERTY_KEY,property);
fragment.setArguments(bundle);
return fragment ;
}
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_flip,container,false);
mProperty =(Property) getArguments().getParcelable(PROPERTY_KEY);
refurbCost = (TextView) getView().findViewById(R.id.refurb);
String refurbCost2 =" " + mProperty.getRefurbCost();
refurbCost.setText(refurbCost2);
You cannot use getView() within the onCreateView method, it will return null. The view that you return at the end of onCreateView() becomes the view that will be returned by getView(). Instead, the view you inflated should be used.
View view = inflater.inflate(R.layout.fragment_flip,container,false);
refurbCost = (TextView) view.findViewById(R.id.refurb);

Starting Activity via Intent is slow / shows considerable delay - why?

I have a very simple MainActivity, and from that Activity I start the other Activity (with theme Dialog so it floats on top of the MainActivity.
The problem is that there is always a delay before the second Activity show up. I'd say it takes almost 1 second for it to show, and there is no code at all in second Activity. The only code in the second Activity is this:
package MyPackage;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
public class JobViewActivity extends Activity {
#Override
protected void onCreate(android.os.Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.jobview);
}
#Override
protected void onResume() {
super.onResume();
}
}
The MainActivity has a ListView with Nodes, and there is a click listener connected to the ListView in the onCreate like this:
public void onCreate(Bundle savedInstanceState)
{
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
_nodeRowAdapter = new NodeRowAdapter(this, _nodes);
listView = (ListView)findViewById(R.id.ListViewNodes);
listView.setAdapter(_nodeRowAdapter);
listView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent i = new Intent(getApplicationContext(), JobViewActivity.class);
startActivity(i);
}
});
But when the ListItem is pressed, and the Click listener is triggered, it takes about 1 second to show the "popup".
The layout isn't very advanced in the popup. Here is the layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:weightSum="1"
android:stretchColumns="1" android:orientation="vertical">
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:stretchColumns="1" android:layout_height="wrap_content" android:id="#+id/tableLayout1">
<TableRow>
<TextView
android:text="Id: "
android:padding="10dip"/>
<TextView
android:text="Ext id: "
android:gravity="right"
android:padding="10dip" />
</TableRow>
</TableLayout>
<RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:id="#+id/relativeLayout1">
<LinearLayout android:id="#+id/linearLayout1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="#E7F3F1">
<Button android:text="Start" android:id="#+id/button1" style="#style/ButtonText" android:layout_weight="1" android:background="#drawable/button_green"></Button>
<Button android:text="Bom" android:id="#+id/button2" style="#style/ButtonText" android:layout_weight="1" android:background="#drawable/button_red"></Button>
<Button android:text="Mer" android:id="#+id/button3" style="#style/ButtonText" android:layout_weight="1" android:background="#drawable/button_yellow"></Button>
<Button android:text="Nav" android:id="#+id/button4" style="#style/ButtonText" android:layout_weight="1"></Button>
</LinearLayout>
</RelativeLayout>
<RelativeLayout android:layout_height="fill_parent" android:layout_width="fill_parent" android:layout_below="#+id/tableLayout1" android:layout_alignParentLeft="true" android:layout_above="#+id/relativeLayout1" android:padding="6dip">
<TextView style="#style/JobViewHeader" android:id="#+id/textView1" android:text="Something: "></TextView>
<TextView style="#style/JobViewHeader" android:id="#+id/TextView2" android:text="Something: " android:layout_below="#+id/textView1"></TextView>
<TextView style="#style/JobViewHeader" android:id="#+id/TextView3" android:layout_marginTop="16dp" android:text="Kund: " android:layout_below="#+id/TextView2"></TextView>
<TextView style="#style/JobViewHeader" android:id="#+id/TextView4" android:text="Something: " android:layout_below="#+id/TextView3"></TextView>
<TextView style="#style/JobViewHeader" android:id="#+id/TextView5" android:text="Something: " android:layout_below="#+id/TextView4"></TextView>
<TextView style="#style/JobViewHeader" android:id="#+id/TextView6" android:text="Something: " android:layout_below="#+id/TextView5"></TextView>
<TextView style="#style/JobViewHeader" android:id="#+id/TextView7" android:text="Something: " android:layout_below="#+id/TextView6"></TextView>
<TextView style="#style/JobViewHeader" android:id="#+id/TextView8" android:layout_marginTop="20dp" android:text="Something: " android:layout_below="#+id/TextView7"></TextView>
<TextView android:layout_height="wrap_content" android:text="TextView" android:layout_width="wrap_content" android:layout_alignBaseline="#+id/textView1" android:layout_alignBottom="#+id/textView1" android:layout_toRightOf="#+id/textView1" android:id="#+id/textViewPickuptime"></TextView>
<TextView android:layout_height="wrap_content" android:text="TextView" android:layout_width="wrap_content" android:layout_alignBaseline="#+id/TextView2" android:layout_alignBottom="#+id/TextView2" android:layout_toRightOf="#+id/TextView2" android:id="#+id/textViewPickupAddress"></TextView>
<TextView android:layout_height="wrap_content" android:text="TextView" android:layout_width="wrap_content" android:layout_above="#+id/TextView4" android:layout_toRightOf="#+id/TextView3" android:id="#+id/textViewCustomer"></TextView>
<TextView android:layout_height="wrap_content" android:text="TextView" android:layout_width="wrap_content" android:layout_alignBaseline="#+id/TextView4" android:layout_alignBottom="#+id/TextView4" android:layout_toRightOf="#+id/TextView4" android:id="#+id/textViewNbrOfPassengers"></TextView>
<TextView android:layout_height="wrap_content" android:text="TextView" android:layout_width="wrap_content" android:layout_above="#+id/TextView6" android:layout_toRightOf="#+id/TextView5" android:id="#+id/textViewRoutine"></TextView>
<TextView android:layout_height="wrap_content" android:text="TextView" android:layout_width="wrap_content" android:layout_alignBaseline="#+id/TextView6" android:layout_alignBottom="#+id/TextView6" android:layout_toRightOf="#+id/TextView6" android:id="#+id/textViewServiceFee"></TextView>
<TextView android:layout_height="wrap_content" android:text="TextView" android:layout_width="wrap_content" android:layout_alignBaseline="#+id/TextView7" android:layout_alignBottom="#+id/TextView7" android:layout_toRightOf="#+id/TextView7" android:id="#+id/textViewHelp"></TextView>
<TextView android:layout_height="wrap_content" android:text="TextView" android:layout_width="wrap_content" android:layout_below="#+id/TextView8" android:layout_alignLeft="#+id/TextView8" android:id="#+id/textViewExtra"></TextView>
</RelativeLayout>
</RelativeLayout>
Im not sure what else to tell you, there isnt much more too it.
Im testing on a device, Samsung Galaxy S2.

Categories

Resources