2 overlayed EditText fields appearing independently - android

I have a problem with my layout of my App. I have 2 Fragments which must be displayed in an Activity. It works fine, but the Layout somehome displays an EditText twice and also behind each other. You can see the hint of the EditText is darker and once I type something in the TextEdit I can see the other EditText independently still visible in the background. Also the TextView and Switch is displayed twice as you can see from the darkness of the appearance:
The Layout files:
activity_main.xml:
<?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:gravity="center_horizontal"
android:orientation="vertical"
tools:context=".QuickSteuerActivity">
<fragment
android:id="#+id/calculation_fragment"
android:name="de.immozukunft.quicksteuer.CalculationFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
/>
<fragment
android:id="#+id/settings_overview_fragment"
android:name="de.immozukunft.quicksteuer.SettingsFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
/> </LinearLayout>
fragment_calculation.xml (This is where the EditText and Switch etc. is)
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/fragment_calculation"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<EditText
android:id="#+id/turnover"
android:defaultValue="0"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/turnover_tax"
android:inputType="numberDecimal"
android:textSize="36sp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="#+id/turnover_vattxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:text="#string/turnover_vattxt"
android:visibility="visible" />
<Switch
android:id="#+id/turnover_vat"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:foregroundGravity="top"
android:title="#string/industrial_tax"
android:visibility="visible" />
</LinearLayout>
<EditText
android:id="#+id/costs"
android:defaultValue="0"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/costs"
android:inputType="numberDecimal"
android:textSize="36sp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="#+id/costs_vattxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:text="#string/turnover_vattxt"
android:visibility="visible" />
<Switch
android:id="#+id/costs_vat"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:title="#string/industrial_tax"
android:visibility="visible" />
</LinearLayout>
<Button
android:id="#+id/btncalculate"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="#string/calculate"
android:textSize="24sp" />
</LinearLayout>
</FrameLayout>
fragment_settings_overview.xml (2.Fragment)
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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:id="#+id/fragment_settings_overview"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/current_settings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:padding="10dp"
android:text="#string/overview_settings"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
</FrameLayout>
I can also provide the Java-files if necessary or any additional files. I just didn't want to bloat the post.
If anybody has got any other additional advices (coding style etc.) please let me know, I am relatively new to Android programming :)
thanks in advance
THE-E
EDIT:
I think I am messing up the layout with the fragment manager. But I am not sure. Because now I see even some PreferenceFragment.
onCreate() of the Activity:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); //Layout
manager = getSupportFragmentManager(); //Fragment-Manager
CalculationFragment calculationFragment = new CalculationFragment(); //create calculation fragment
SettingsOverviewFragment settingsOverviewFragment = new SettingsOverviewFragment(); //create settings overview fragment
calculationFragment.setArguments(getIntent().getExtras()); //I don't know what happens here
settingsOverviewFragment.setArguments(getIntent().getExtras()); //I don't know what happens here either
FragmentTransaction transaction = manager.beginTransaction();
transaction.add(R.id.calculation_fragment, calculationFragment); //add calculation fragment to the fragment transaction
transaction.add(R.id.settings_overview_fragment, settingsOverviewFragment); //add settings overview fragment to the fragment transaction
transaction.commit(); //commit the transaction
}

Change height and width of both the fragments to wrap_content and see if it works for you ?

I've used Hint in the second text and TEXT in the first
android:hint="#string/turnover_tax"
To display the text dimly use the Hint instead of the Netscape
android:hint="Your String"
android:text="Your String"
I've used Hint in the second text and TEXT in the first
android:hint="#string/turnover_tax"
To display the text dimly use the Hint instead of the Netscape
android:hint="Your String"
android:text="Your String"
Using the Hint means a tip which must be written in the EditText
When you type Netscape in the Netscape EditText, the embedded grid will appear in the EditText and can be set or changed
But when you write a hint it will disappear once you start typing in the EditText that contains it

I found my mistake. I was adding in the onCreate of the main Activity a Fragment on top of the already set Fragment using the FragmentManager. The Fragment was already set in the layout ( itself, that is why I don't need to use a FragmentManager (fragment_calculation.xml).
All I had to do is set the layout of the activity and I was done.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); //Layout
}
this was my onCreate()-Method.
thanks for your help! :)

Related

TextView is gone and Button is visible

Textview items are not visible. The Button below them is.
Tried changing the LinearLayout with RelativeLayout, changed the match_parent and content with 0dp. None of them worked. Only the button shows in the right spot as though the TextViews are there but invisible. These views are called in the onCreate() of the Activity.
<?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="wrap_content"
android:orientation="vertical"
tools:context=".EnterData">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/tvDateIn"
android:layout_marginStart="15dp"
android:layout_marginTop="15dp"
tools:text="Date"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/tvDescIn"
android:layout_marginTop="15dp"
android:layout_marginStart="15dp"
tools:text="Description"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/tvAmountIn"
tools:text="California"
android:layout_marginTop="15dp"
android:layout_marginStart="15dp"
android:textColor="#000"
android:textSize="17sp"/>
<Button
android:id="#+id/btnSendData"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="30dp"
android:text="Send Data"/>
</LinearLayout>
You try to use android:text instead of tools:text. tools:textonly visible in the Android Studio.
Or you should use yourTextView.setText("yourText") if you are using tools:text.
Instead of using tool:text in xml use android:text="abc" in textView.
As tool:text is used for android studio layout preview . It does not show text when you run your application .
While android:text is used to set text to textview, button etc.
Yep, it was all working and just placing android:text showed it.
Thank you very much.

Android Studio - Scrollview moves outside the screen on keyboard open

I want to make a chat screen which has an EditText and a Button at the bottom (wrapped in a LinearLayout), and a ScrollView for the messages at the top. The problem is that when the user taps the EditText and the keyboard opens, the ScrollView will go off screen as a result of moving up. I would like to move the Layout (with the EditBox and the Button) above the keyboard and the ScrollView to be resized to fit the screen. The problem is shown on the pictures below:
As you can see, the line that writes "Chat" (left image) has disappeared in the right image.
I use this XML code:
<?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:padding="15sp"
android:orientation="vertical"
android:background="#ccdcf7"
tools:context="com.orionz.sockettest.ChatActivity">
<ScrollView
android:id="#+id/scroll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="15"
android:isScrollContainer="false">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/chatBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="Chat\n"
android:textColor="#000000"
android:textIsSelectable="true"
android:textSize="22dp" />
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center|bottom"
android:orientation="horizontal">
<EditText
android:id="#+id/msgInput"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.8"
android:ems="10"
android:hint="Message..."
android:inputType="text" />
<Button
android:id="#+id/sendButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:background="#drawable/mybutton"
android:padding="5sp"
android:text="Send"
android:textColor="#ffffff"
android:textSize="20sp" />
</LinearLayout>
</LinearLayout>
I have seen many answers such as setting the android:windowSoftInputMode but none has worked. I use Android Studio. Any help would be appreciated.
Try to replace the ScrollView with a ListView like this :
<ListView
android:id="#+id/list_view"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1">
</ListView>
store all the messages in an ArrayList, and set an adapter to the ListView you made :
ListView listView=(ListView) findViewById(R.id.list_view);
ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,ArrayList);
listView.setAdapter(adapter);
Finally, add a listenner on your Button writing these lines :
EditText editText= (EditText) findViewById(R.id.msgInput);
ArrayList.add(editText.getText().toString());
adapter.notifyDataSetChanged();
Finally, I found what was wrong in my case.
The theme was full screen. In the style of the activity I had this line that caused the problem:
<item name="android:windowFullscreen">true</item>
In the java code, I gave a command to open the keyboard on the start of the activity:
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
which was also part of the problem
After adding the adjustResize property to the activity in the manifest, everything worked fine:
android:windowSoftInputMode="adjustResize"
Wrap Scrollview to the whole layout.
i.e place editText and button inside Scrollview and set scrollView Height to android:layout_height="match_parent"

ChildFragmentManager.findFragmentByID() returns null on android 4.4.2

I developed an app, that uses Fragments as part of a Fragment.
public class LoginFragment extends Fragment
EditTextWithCameraButtonFrag userNameFrag;
EditTextWithCameraButtonFrag passwordFrag;
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
userNameFrag = (EditTextWithCameraButtonFrag)getChildFragmentManager()
.findFragmentById(R.id.fragment_username);
passwordFrag = (EditTextWithCameraButtonFrag) getChildFragmentManager()
.findFragmentById(R.id.fragment_password);
EditTextWithCameraButtonFrag is a subtype of Fragment.
This code works like a charm, running on android 5.1.1.
However, running it on Android 4.4.2 returns in userNameFrage and passwordFrag being null. So it seems, that the returned Child FragmentManager does not find the fields.
Is there any thing to consider when using getChildFragmentManager()with 4.4.3?
Thanks in advance!
EDIT:
This is the main fragment's XML:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/huge"
android:orientation="vertical" >
<TextView
android:id="#+id/login_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/activity_vertical_margin"
android:gravity="center"
android:textColor="#color/white"
android:textSize="40dp" />
<fragment
android:id="#+id/fragment_username"
android:name="com.example.app.fragments.EditTextWithCameraButtonFrag"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<fragment
android:id="#+id/fragment_password"
android:name="com.example.app.fragments.EditTextWithCameraButtonFrag"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="#+id/login_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="#dimen/huge"
android:layout_marginStart="#dimen/huge"
android:layout_marginTop="#dimen/normal"
android:padding="#dimen/half"
android:text="Login" />
</LinearLayout>
And this the sub fragment's:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/editText_with_button_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:id="#+id/text_input_field"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:alpha="0.75"
android:background="#drawable/edit_text_login_top"
android:inputType="text"
android:padding="#dimen/normal" />
<Button
android:id="#+id/scan_text_view"
android:layout_width="wrap_content"
android:background="#android:color/transparent"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/text_input_field"
android:layout_alignTop="#+id/text_input_field"
android:layout_alignBottom="#+id/text_input_field"
/>
</RelativeLayout>
I just solved it- kinda.
After a LOT of reading it seems like it's possible to declare nested fragments via XML, but is not best practice.
So I decided to include FrameLayouts in the XML, and add the nested
Fragments via FragmentTransaction.
<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:gravity="center" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/huge"
android:orientation="vertical" >
<TextView
android:id="#+id/login_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/activity_vertical_margin"
android:gravity="center"
android:textColor="#color/white"
android:textSize="40dp" />
<FrameLayout
android:id="#+id/fragment_username"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="#+id/fragment_password"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="#+id/login_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="#dimen/huge"
android:layout_marginStart="#dimen/huge"
android:layout_marginTop="#dimen/normal"
android:padding="#dimen/half"
android:text="Login" />
</LinearLayout>
</RelativeLayout>
And in the main fragment's onCreate:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// create userNameFrag
EditTextWithCameraButtonFrag userfragment = new EditTextWithCameraButtonFrag();
getChildFragmentManager().beginTransaction().replace(R.id.fragment_username, userfragment).commit();
// create passwordFrag
EditTextWithCameraButtonFrag passfragment = new EditTextWithCameraButtonFrag();
getChildFragmentManager().beginTransaction().replace(R.id.fragment_password, passfragment).commit();
}
This seems to work pretty good and- another plus- I also got rid of the the duplicate id bug.
From the code it is not clear where are these two fragments added:
1) Added in activity (in xml or in onCreate method)
Then this fragments are associated to fragemnt manager which belongs to Activity. You should use getActivity().getFragmentManager().find...
2) Fragemnts added in fragemnt xml layout
then they will be available after calling fragments onViewCreated method
Use getChildFragmentManager() for fragments which are defined in xml layout of this fragment or for fragments which are added by this getChildFragmentManager() fragment manager.

Android - Custom Keyboard on manually inflated listview row not showing

Good day.
I have an android application. In my application, I have a custom listView with 5 columns that are textViews. The user can click the rows, once he does, the row layout will change, changing the last 2 textViews to EditTexts. I then register the new EditTexts onto my custom keyboard taken from this example - kindly note that I did a functional copy-paste of his example with regards to the custom keyboard class and how to make it work in the main layout. However, when I click the EditText in the row, my custom keyboard does not show up at all.
I have a global variable as such:
CustomKeyboard mCustomKeyboard;
And in my onCreate() method in the activity, I do:
mCustomKeyboard= new CustomKeyboard(this, R.id.keyboardview, R.xml.custom_keyboard);
This is my layout, I have the KeyboardView at the bottom of the Layout:
<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:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context=".SearchResult" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- A lot of views go here, enclosed in my linear layout -->
</LinearLayout>
<android.inputmethodservice.KeyboardView
android:id="#+id/keyboardview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:visibility="gone" />
</RelativeLayout>
Here is the code that changes the layout. What I do is that I take the row values from the old layout, get the new layout search_result_inflate, then set the texts of the new layout using the values I got. Kindly note the mCustomKeyboard.registerEditText(R.id.qtyInputSearchResult); line after inflating the layout:
private void changeLayout(final View view){
//get views from old layout
TextView textViewQuantity = (TextView)view.findViewById(R.id.qtyInput);
TextView textViewDiscountReq = (TextView)view.findViewById(R.id.discInput);
TextView textViewName = (TextView)view.findViewById(R.id.dialogItemName);
TextView textViewPrice = (TextView)view.findViewById(R.id.price);
TextView textViewDiscount = (TextView)view.findViewById(R.id.discount);
//store values in strings
String itemName = textViewName.getText().toString();
String itemPrice = textViewPrice.getText().toString();
String itemDiscount = textViewDiscount.getText().toString();
String itemQty = textViewQuantity.getText().toString();
String itemDisc = textViewDiscountReq.getText().toString();
//set the view to gone
textViewQuantity.setVisibility(View.GONE);
textViewDiscountReq.setVisibility(View.GONE);
textViewName.setVisibility(View.GONE);
textViewPrice.setVisibility(View.GONE);
textViewDiscount.setVisibility(View.GONE);
//get the old layout
LinearLayout ll_inflate = (LinearLayout)view.findViewById(R.id.search_result_layout);
//get the inflate/new view
View child = getLayoutInflater().inflate(R.layout.search_result_inflate, null);
//get the views in the new view, populate them
TextView newName = (TextView)child.findViewById(R.id.dialogItemName);
newName.setText(itemName);
TextView newDiscount = (TextView)child.findViewById(R.id.discount);
newDiscount.setText(itemDiscount);
TextView newPrice = (TextView)child.findViewById(R.id.price);
newPrice.setText(itemPrice);
EditText qtyInput = (EditText)child.findViewById(R.id.qtyInputSearchResult);
qtyInput.setText(itemQty);
EditText discInput = (EditText)child.findViewById(R.id.discInputSearchResult);
discInput.setText(itemDisc);
//show new layout
ll_inflate.removeAllViews();
ll_inflate.removeAllViewsInLayout();
ll_inflate.addView(child);
mCustomKeyboard.registerEditText(R.id.qtyInputSearchResult);
}
Here is my search_result_inflate.xml file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/search_result_inflate"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
android:minHeight="50dp"
android:orientation="horizontal"
android:padding="1dip"
android:weightSum="1" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="horizontal"
android:padding="1dip" >
<TextView
android:id="#+id/dialogItemName"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginRight="2dp"
android:layout_weight="0.54"
android:gravity="center"
android:text="Item Name"
android:textSize="23sp" />
<TextView
android:id="#+id/price"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginRight="2dp"
android:layout_weight="0.14"
android:gravity="center"
android:text="Price"
android:textSize="23sp" />
<TextView
android:id="#+id/discount"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginRight="2dp"
android:layout_weight="0.10"
android:gravity="center"
android:text="Discount"
android:textSize="23sp" />
<EditText
android:id="#+id/qtyInputSearchResult"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginRight="2dp"
android:layout_weight="0.14"
android:background="#layout/edittext_selector"
android:gravity="center"
android:hint="qtyInput"
android:textColorHighlight="#color/white_opaque"
android:textSize="23sp" >
</EditText>
<EditText
android:id="#+id/discInputSearchResult"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.11"
android:background="#layout/edittext_selector"
android:focusable="true"
android:focusableInTouchMode="true"
android:gravity="center"
android:hint="discInput"
android:textColorHighlight="#color/white_opaque"
android:textSize="23sp" />
</LinearLayout>
</LinearLayout>
As you can see, I have 2 editTexts and I registered qtyInputSearchResult to the custom keyboard class. However, the custom keyboard does not show up.
I also tried to use the custom keyboard class on an editText in another activity and it works just fine. Am I missing something here? I'm confused as to why the custom keyboard does not show up properly.
Any help is very much appreciated, thank you.
Got it, I placed the keyboard layout in the search_result_inflate.xml like so:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/search_result_inflate"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
android:minHeight="50dp"
android:orientation="horizontal"
android:padding="1dip"
android:weightSum="1" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="horizontal"
android:padding="1dip" >
<!-- a lot of components here -->
</LinearLayout>
<android.inputmethodservice.KeyboardView
android:id="#+id/keyboardview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:visibility="gone" />
</RelativeLayout>

ANDROID: SQLite with ListViews

-- This is my layout thus far for the input --
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<EditText
android:id="#+id/etClassName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:hint="#string/className"/>
<EditText
android:id="#+id/etAssignmentName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:ems="10"
android:hint="#string/assignmentName"/>
<EditText
android:id="#+id/etDueDate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:layout_marginBottom="20dp"
android:hint="#string/dueDate" />
<EditText
android:id="#+id/etNotes"
android:layout_width="match_parent"
android:layout_height="194dp"
android:ems="10"
android:inputType="textMultiLine"
android:layout_marginBottom="5dp"
android:hint="#string/notes"/>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="horizontal">
<Button
android:id="#+id/bAddAssignments"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/addAssignment"
android:layout_weight="1" />
<Button
android:id="#+id/bViewAssignments"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/viewAssignments"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
-- Clicking the add button brings you to this page which is supposed to list the assignment name that you can click to view your assignment --
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.63" >
</ListView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/bNewAssignment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/newAssignment" />
<Button
android:id="#+id/bdeleteAssignment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/deleteAssignment" />
</LinearLayout>
</LinearLayout>
My problem is that I don't know how to populate the second layout when my first layout keeps track of the data. How does the second layout know what the user inputted etc in order to populate the listview
I currently have a dbadapter class(with helper class inside), an entry class(creates entry objects), and an assignmentclass(supposed to display listview)
Any Ideas, please?
Pass the data you need in an Intent bundle.
When you set the intent, put the data you need in ther next class as an extra (assuming strings here, but can be other forms):
Intent myIntent = new Intent(YourActivity.this, NewActivity.class);
myIntent.putExtra("Data1", data1var);
myIntent.putExtra("Data2", data2var);
YourActivity.this.startActivity(myIntent);
In the new class:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle extras = getIntent().getExtras();
if (extras != null) {
String value1 = extras.getString("Data1");
String value2 = extras.getString("Data2");
}
//use your passed strings
}
Your description of the problem is rather vague. I can refer you to one of the tutorials Lars Vogella made about how to use SQLLite together with a ListView. They explain everything nice and simple. I am sure that you will find your answer there!
Update:
onClickListener of the Add-button in InputActivity:
Add your user input to the database (with you DatabaseHelper)
List item Start you second activity including the ListView
onCreate of the ListActivity:
Create for example an Array
Let your DatabaseHelper fill the array with the records you want in the database
Create an Adapter giving you filled array with it

Categories

Resources