I'm currently testing my code for situations where a RecyclerView.Adapter needs additional information to be displayed in it. Using the code below which is inside onBindViewHolder, I was able to make this work.
TableRow row = new TableRow(mCtx);
row.setLayoutParams(new TableLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
row.setOrientation(LinearLayout.VERTICAL);
TextView lbl = new TextView(mCtx);
lbl.setText("Desc1");
TextView lbl2 = new TextView(mCtx);
lbl2.setText("54.77");
row.addView(lbl);
row.addView(lbl2);
holder.binding.tblTicketItemDetails.addView(row);
That code is always called inside OnBindViewHolder to simulate that each item have additional info in them. If I keep creating an item by pressing a Button, the additional info increases for each item.
How do I target the specific adapter's layout while using DataBinding?
This is the layout that I am using for RecyclerView.Adapter.
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<variable
name="ticket_item"
type="com.example.com.TicketItem" />
</data>
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TableRow
android:id="#+id/tableRow6"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="8dp"
android:weightSum="2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="#+id/lblTicketItemName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="8dp"
android:text="#{ticket_item.description}"
android:textColor="#color/black"
android:textSize="18sp"
android:textStyle="bold"
tools:text="Test Text" />
<TextView
android:id="#+id/lblTicketItemPrice"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="end"
android:padding="8dp"
android:text="#{ticket_item.price}"
android:textColor="#color/black"
android:textSize="18sp"
android:textStyle="bold"
tools:text="Test Text" />
</TableRow>
<TableLayout
android:id="#+id/tblTicketItemDetails"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/tableRow6">
</TableLayout>
</android.support.constraint.ConstraintLayout>
</layout>
I want to add a TableRow with 2 TextViews in tblTicketItemDetails if needed. What is the best way to do this? If I can't do it while using DataBinding, then I would switch to the old way.
I usually add dynamic views like this using Databinding:
#BindingAdapter({"addDynamicView", "position"})
public static void addDynamicView(TableLayout layout, TicketItem item, int position) {
// LayoutInflater inflater = LayoutInflater.from(layout.getContext()); // if you need layout inflater
for (int i = 0; i <= position; i++) { // loop to whatever condition you have
TextView lbl = new TextView(layout.getContext());
lbl.setText("Desc1");
layout.addView(lbl);
}
}
Modify TableLayout in xml,
<TableLayout
android:id="#+id/tblTicketItemDetails"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/tableRow6"
app:addDynamicView = "#{ticket_item}"
app:position = "#{position}">
Declare a new variable in xml,
<variable
name="position"
type="int" />
Send position from Java to xml
holder.binding.setVariable(BR.position, position);
or
holder.binding.setPosition(position);
Related
I have a view like this:
<?xml version="1.0" encoding="utf-8"?>
<layout 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">
<data>
</data>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="#+id/sample_icon_iv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:src="#drawable/active_state"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="#+id/sample_item_bar_iv"
android:layout_width="128dp"
android:layout_height="1dp"
android:background="#color/brown_grey"
app:layout_constraintBottom_toBottomOf="#id/sample_icon_iv"
app:layout_constraintStart_toEndOf="#id/sample_icon_iv"
app:layout_constraintTop_toTopOf="#id/sample_icon_iv"
/>
<TextView
android:id="#+id/leave_planner_item_date_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="26 March"
app:layout_constraintEnd_toStartOf="#+id/sample_item_bar_iv"
app:layout_constraintStart_toStartOf="#+id/sample_icon_iv"
app:layout_constraintTop_toBottomOf="#+id/sample_icon_iv"
tools:text="26 March" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
I need to inflate this view x times and show those evenly distributed in a horizontal scrollable fashion. I tried adding weight 1 to the inflated views before adding to the parent, but still doesn't seem to work. I also face spacing issues between the bar and the next icon. But if I remove the margin, I am not able to center the text under the icon.
This is how I would like to see the views
How do I achieve this?
Wrap your views in LinearLayout. Determine how many childs you want it to have and then set it like so:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="3"
android:orientation="horizontal">
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
This example will create 3 buttons that take up the entire width of the screen, each button will get 1/3 of the screen width.
To do so programmatically:
LinearLayout layout = findViewById(R.id.yourLayoutID);
Button b = new Button(); // Or, if you want something more complicated than a simple object, you can do View v = inflater.inflate(R.layout.your_layout, null);
LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.MATCH_PARENT);
p.weight = 1;
b.setLayoutParams(p);
layout.addView(b);
that's the general idea
I'm currently learning the basics of Android programming. I'm able to create a static app with one page and a few buttons. The next step is learn to dynamically create apps, like i'm used to in webapplications.
What i'm trying to do is create a simple facebook-like app with some timeline objects, with some text, a like button and the date it was placed. There is a simple NodeJS server which responds to a http GET request with a JSON file. Which is parsed and for each object in the array there should be a timeline object created, just like there is on facebook.
On my homepage i'm creating some dynamic content to contain the timeline objects.
ConstraintLayout container = activity.findViewById(R.id.container);
container.removeAllViews();
TextView nav_txt = activity.findViewById(R.id.nav_txt);
nav_txt.setText("Home");
swipeRefreshLayout = new SwipeRefreshLayout(activity);
ScrollView scrollView = new ScrollView(activity);
container.addView(swipeRefreshLayout);
scrollView.setLayoutParams(new ConstraintLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ConstraintLayout.LayoutParams.MATCH_PARENT));
linearLayout = new LinearLayout(activity);
linearLayout.setOrientation(LinearLayout.VERTICAL);
linearLayout.setId(R.id.linearLayout);
swipeRefreshLayout.addView(scrollView);
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
#Override
public void onRefresh() {
refreshData();
}
});
scrollView.addView(linearLayout);
This is easy, the views don't need any constraints, because everything is the same height as the parent.
The timeline objects are more complicated, with a lot of constraints and children with different sizes, so i thought, i create a custom XML file with the timeline object already defined, grab it by the ID and modify it to suit my needs.
My timeline_message.xml looks like this:
<android.support.constraint.ConstraintLayout 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.support.constraint.ConstraintLayout
android:id="#+id/timeline_msg"
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_marginTop="8dp"
android:background="#color/backgroundColor"
app:layout_constraintTop_toTopOf="parent">
<Button
android:id="#+id/like_btn"
android:layout_width="90dp"
android:layout_height="91dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:background="#color/colorPrimary"
android:text="Like"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/username"
android:layout_width="272dp"
android:layout_height="55dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:gravity="center_vertical"
android:text="text"
android:textAlignment="center"
android:textColor="#color/colorPrimary"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/like_btn"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/date"
android:layout_width="91dp"
android:layout_height="40dp"
android:layout_marginStart="20dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:gravity="center_vertical"
android:text="TextView"
android:textAlignment="center"
android:textColor="#color/colorPrimary"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.003"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/username"
app:layout_constraintVertical_bias="0.0" />
</android.support.constraint.ConstraintLayout>
And i'm trying to grab the object + children like this:
LinearLayout linearLayout = activity.findViewById(R.id.linearLayout);
ConstraintLayout timelineMsg = activity.findViewById(R.id.timeline_msg);
linearLayout.addView(timelineMsg);
But nothing happens. Is an approach like this possible? Or do you need to write all that code manually with layoutparams and constraints e.t.c.?
You are close you just forgot something
If you want to use your timeline_message.xml layout you need to inflate it before
Example :
LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
Then you can use your inflater for inflate a view
View view = inflater.inflate(R.layout.timeline_message, null);
You can now use your view for find your element
ConstraintLayout timelineMsg = view.findViewById(R.id.timeline_msg);
For finish you can add your inflate view to your container with
linearLayout.addView(view);
I am trying to create a dialog which uses a custom view which also has a number of different behaviours attached, which is why I extended AlertDialog instead of using a builder.
The code that creates the view looks like this looks like this
class MyTaskCreateDialog extends AlertDialog implements DialogInterface.OnCancelListener {
public MyTaskCreateDialog(Context ctx, TaskItem item, List<Person> people, IOnFinishListener listener) {
super(ctx) {
View view = LayoutInflater.from(ctx).inflate(Resource.Layout.dialog_my_task_create, null, false);
setView(view);
setCancelable(true);
setOnCancelListener(this);
setCanceledOnTouchOutside(true);
assign_views(view); //this assigns the views to the local variables
attach_listeners();
refresh_view();//this updates the view with data
}
the above uses this layout file
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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:padding="#dimen/app_padding">
<android.support.design.widget.TextInputLayout
android:id="#+id/my_task_create_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/app_margin"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/my_task_create_hint_title" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="#+id/my_task_create_description"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
app:layout_constraintEnd_toEndOf="#+id/my_task_create_title"
app:layout_constraintStart_toStartOf="#+id/my_task_create_title"
app:layout_constraintTop_toBottomOf="#+id/my_task_create_title">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/my_task_create_hint_description" />
</android.support.design.widget.TextInputLayout>
<TextView
android:id="#+id/my_task_create_assignee_caption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/my_task_create_caption_assignee"
app:layout_constraintBottom_toBottomOf="#+id/my_task_create_assignee"
app:layout_constraintStart_toStartOf="#+id/my_task_create_description"
app:layout_constraintTop_toTopOf="#+id/my_task_create_assignee" />
<Spinner
android:id="#+id/my_task_create_assignee"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/app_margin"
android:checked="true"
android:padding="#dimen/app_padding"
android:textOff="#string/my_task_create_toggle_manually"
android:textOn="#string/my_task_create_toggle_automatically"
app:layout_constraintEnd_toEndOf="#+id/my_task_create_description"
app:layout_constraintStart_toEndOf="#+id/my_task_create_assignee_caption"
app:layout_constraintTop_toBottomOf="#+id/my_task_create_description"
tools:listitem="#android:layout/simple_spinner_item" />
<Button
android:id="#+id/my_task_create_create_task"
style="#style/Widget.AppCompat.Button.Borderless.Colored"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/app_margin"
android:text="#string/my_task_create_button_create"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/my_task_create_cancel"
app:layout_constraintTop_toBottomOf="#+id/my_task_create_assignee" />
<Button
android:id="#+id/my_task_create_cancel"
style="#style/Widget.AppCompat.Button.Borderless.Colored"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/app_margin"
android:text="#string/my_task_create_button_cancel"
app:layout_constraintEnd_toStartOf="#+id/my_task_create_create_task"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/my_task_create_assignee" />
</android.support.constraint.ConstraintLayout>
which creates a dialog with big padding at the bottom.
in fact is I change the background of the ConstraintLayout to be greyish, then the bottom half of the dialog seems to be the default color.
the result of the above looks like this:
now I know that some space is saved for the buttons (I do not use those, I use custom ones from the layout file), but how can I make the rest of the space disappear and make my dialog wrap its content?
I was having the same problem, and the only solution that worked for me is to add the following code into all Views inside of ConstraintLayout:
android:layout_height="0dp"
app:layout_constraintHeight_default="wrap"
Those sentences replace this:
android:layout_height="wrap_content"
My requirement is: After click on + icon , a new row should add dynamically and able to access its ids. Please give suggestions to implement it.
The easiest way to do this would be to display the items in a ListView/RecyclerView and simply add the new item into adapter and let the adapter handle adding the new row Item. You don't have to care about the items id and can simply use the adapters position as an id.
When you create a view programmatically, you can assign the View id by calling View.setID(), which can be any int (it must be unique). I wouldn't recommend this approach because it'll get very tedious to track the id's and the data the items contains. Using RecyclerView/ListView elevates this problem by separating the data from the presentation layers.
This is the code to add new row dynamically, but not able to create new ids
public void onAddField(View v) {
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View rowView = inflater.inflate(R.layout.field, null);
// Add the new row before the add field button.
parentLinearLayout.addView(rowView, parentLinearLayout.getChildCount() - 6);
}
in field.xml
<?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="50dp"
android:orientation="horizontal" >
<EditText
android:id="#+id/grid_Itemcode"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3"
android:inputType="textPhonetic"
android:hint="Code" />
<EditText
android:id="#+id/grid_itemdesc"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="5"
android:inputType="textPersonName"
android:hint="Description" />
<EditText
android:id="#+id/grid_itemQty"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:inputType="phone"
android:hint="Qty" />
<EditText
android:id="#+id/grid_itemRate"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:inputType="phone"
android:hint="Rate" />
<Button
android:id="#+id/delete_button"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_weight="1"
android:background="#android:drawable/ic_delete"
android:onClick="onDelete"/>
</LinearLayout>
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>