I have a listview that is displayed to the user, and I am figuring out ways to make the listview non-infinite, and limit it to 25 items. I am also trying restrict user from being able to display a number in the EditText. I have tried to add android:inputType="text|textNoSuggestions" , in list view but this has proven to be ineffective.
<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:background="#drawable/white_wallpaper"
>
<ListView
android:id="#+id/listMessages"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/divider"
android:divider="#null"
android:dividerHeight="0dp"
android:inputType="text|textNoSuggestions"
android:padding="0dip"
android:stackFromBottom="true"
android:transcriptMode="alwaysScroll"
tools:listitem="#layout/message_left" />
<RelativeLayout
android:id="#+id/divider"
android:layout_width="fill_parent"
android:layout_height="1dip"
android:background="#color/off_white"
android:layout_above="#+id/relSendMessage" />
<RelativeLayout
android:id="#+id/relSendMessage"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:background="#ddd"
android:paddingLeft="10dp"
android:layout_alignParentBottom="true">
<EditText
android:id="#+id/messageBodyField"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignBottom="#+id/sendButton"
android:layout_alignTop="#+id/sendButton"
android:layout_marginBottom="-4dp"
android:layout_marginRight="10dp"
android:inputType="text|textNoSuggestions"
android:layout_toLeftOf="#+id/sendButton"
android:background="#android:color/white"
android:hint="#string/message_elipses"
android:textColor="#000000"
android:textColorLink="#adefda"
android:textSize="14sp" />
<Button
android:id="#+id/sendButton"
android:layout_width="72dp"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_margin="4dp"
android:background="#drawable/button_send" />
</RelativeLayout>
<Button
android:id="#+id/iSchedule"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:alpha="0.7"
android:background="#C11B17"
android:text="Schedule"
android:textColor="#f2f2f2"
android:textSize="20sp"
android:textStyle="bold"
android:typeface="serif" />
</RelativeLayout>
Any suggestions would be greatly appreciated.
Update:
As far as limiting listview items, I have the below code:
Below is how the listview is displayed programmatically:
messagesList = (ListView) findViewById(R.id.listMessages);
messageAdapter = new MessageAdapter(this);
WOuld the below work:
#Override
public int getCount() {
messagesList.setAdapter(messageAdapter);
return 25;
}
So to handle your edit text problem, you can use this
<EditText
...
android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
/>
Now the above characters are the only one that can be entered into the EditText. Also you can change the keyboard type in the android:inputType.
Additionally you wanted to limit the number of entries in a ListView. In the BaseAdapter method of your code, change this:
#Override
public int getCount() {
return 25;
}
UPDATE:
Well what you can do is create a custom ArrayAdapter and modify the getCount method there. As getCount() is in a different class altogether, you just want to alter the maximum 25 there and then set the list view to that adapter. You may want to take a look here for more uses of ArrayAdapters.
Related
I am in the process of learning android/java and I am creating an application that does conversions. The issue that I am running into is that there are a lot of different combinations that can be made as the user has to select a unit to convert from and one to convert to. I need a solution that can determine which unit has been chosen so I can do a calculation with values that are assigned to each unit. Here is the code.
Thanks in advance for any response.
Dom.
<?xml version="1.0" encoding="utf-8"?>
<android.widget.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=".MainActivity">
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="15dp"
android:text="Conversions"
android:textSize="20sp" />
<TextView
android:id="#+id/weight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/title"
android:text="Weight"
android:textSize="20sp"
android:layout_marginLeft="10dp"/>
<Spinner
android:id="#+id/spin1"
android:layout_width="150dp"
android:layout_height="50dp"
android:layout_below="#+id/weight"
>
</Spinner>
<Spinner
android:id="#+id/spin2"
android:layout_width="150dp"
android:layout_height="50dp"
android:layout_below="#+id/weight"
android:layout_toRightOf="#id/to">
</Spinner>
<TextView
android:id="#+id/to"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/weight"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_toRightOf="#id/spin1"
android:text="-->"
android:textSize="25sp" />
<EditText
android:id="#+id/val1"
android:layout_width="75dp"
android:layout_height="60dp"
android:inputType="numberDecimal"
android:layout_below="#id/spin1"
android:layout_marginTop="10dp"
android:layout_toLeftOf="#id/to"
/>
<TextView
android:id="#+id/answer"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:text=""
android:layout_toRightOf="#+id/val1"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_below="#+id/spin1"
/>
<Button
android:id="#+id/calc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Calculate"
android:textAllCaps="false"
android:layout_below="#id/spin2"
android:layout_alignParentRight="true"
android:layout_marginTop="15dp"
android:layout_marginRight="15dp"
/>
</android.widget.RelativeLayout>`
Java:
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Spinner spin1 = findViewById(R.id.spin1);
String[] items1 = {"Gram", "Kilogram", "Stone", "Tonne", "Pound", "Ounce",};
ArrayAdapter<String> adapter1 = new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item, items1);
spin1.setAdapter(adapter1);
Spinner spin2 = findViewById(R.id.spin2);
String[] items2 = {"Gram", "Kilogram", "Stone", "Tonne", "Pound", "Ounce",};
ArrayAdapter<String> adapter2 = new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item, items2);
spin2.setAdapter(adapter2);
}
}
I'm envisioning an app that converts an input distance between different units of measurement (feet, miles, meters, etc...). Here's what I'd do:
Create two variables of type double, called inputConversionFactor and outputConversionFactor. When the user selects an option from each spinner, this sets the corresponding conversion factor value.
When an input distance is entered, internally convert this distance to meters using inputConversionFactor. Then use outputConversionFactor to convert from meters to the desired output unit.
By doing it this way, you're breaking down the problem into two discrete steps. You don't have to worry about how to convert between any two arbitrary units, since you're always converting the input to meters and then the meters to the output unit type.
Can't say it much more clearly than in the title. I have an EditText wrapped by a Text Input Layout. I'm trying to trigger an event when that EditText loses focus. However, once the event listener is applied, the TextInputLayout no longer animates the text, it just sits on the editText line until information is entered, at which time it does animate. Can anyone give me some insight as to why this is happening?
Edit: Layout file.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/card_drawable"
android:gravity="center"
android:padding="11dp"
android:text="The fields below will be used to calculate your training maxes. Please enter your best rep record, or 1RM, for each lift. Training maxes will be determined using the following formula provided in Beyond 5/3/1: \n(Weight Lifted x Reps X .0333 + Weight Lifted)" />
<LinearLayout
android:id="#+id/squat_container"
style="#style/linear_layout_style">
<android.support.design.widget.TextInputLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1">
<EditText
android:id="#+id/squatWeight_editText"
style="#style/editText_floating_label"
android:hint="Squat Weight" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="#+id/txtInputLayoutSquat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1">
<EditText
android:id="#+id/squatReps_editText"
style="#style/editText_floating_label"
android:hint="Repetitons" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/bench_container"
style="#style/linear_layout_style">
<android.support.design.widget.TextInputLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1">
<EditText
android:id="#+id/bechpressWeight_editText"
style="#style/editText_floating_label"
android:hint="Bench Press Weight" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1">
<EditText
android:id="#+id/benchpressReps_editText"
style="#style/editText_floating_label"
android:hint="Repetitons" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/deadlift_container"
style="#style/linear_layout_style">
<android.support.design.widget.TextInputLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1">
<EditText
android:id="#+id/deadliftWeight_editText"
style="#style/editText_floating_label"
android:hint="Deadlift Weight" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1">
<EditText
android:id="#+id/deadliftReps_editText"
style="#style/editText_floating_label"
android:hint="Repetitons" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/ohp_container"
style="#style/linear_layout_style">
<android.support.design.widget.TextInputLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1">
<EditText
android:id="#+id/ohpWeight_editText"
style="#style/editText_floating_label"
android:hint="Overhead Press Weight" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1">
<EditText
android:id="#+id/ohpReps_editText"
style="#style/editText_floating_label"
android:hint="Repetitons" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
</LinearLayout>
I had to deal with the same issue.
The workaround I used was using a custom EditText and adding a custom listener to it to be called when the onFocusChanged method is fired.
Custom EditText (Boiler plate code is not shown)
public class EditTextPlus extends AppCompatEditText {
//This is the custom listener you will use
public OnFocusChangeListener customListener;
#Override
protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
super.onFocusChanged(focused, direction, previouslyFocusedRect);
if (customListener != null) {
customListener.onFocusChange(this, focused);
}
}
}
In Activity/Fragment
yourEditText.customListener = new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View v, boolean hasFocus) {
//Do your stuff
}
}
Don't forget to use the custom EditText in the xml as well and not the default EditText.
This doesn't solve the issue but does give some insight (I'll update if I figure out a solution), but seems like the animated hint is dependent on OnFocusChangedListener, which gets overwritten when you add your own listener.
https://code.google.com/p/android/issues/detail?id=175344
EDIT:
Per https://code.google.com/p/android/issues/detail?id=178693...
We're now using a different way to determine if the EditText is focused. For now do something like:
TextInputLayout inputLayout = ...;
EditText editText = inputLayout.getEditText();
final OnFocusChangeListener existing = editText.getOnFocusChangeListener();
editText.setOnFocusChangeListener(new OnFocusChangeListener() {
public void onFocusChange(View view, boolean focused) {
existing.onFocusChange(view, focused);
// Your custom logic
}
});
I'm working on my first Android project, which means that I'm not that familiar with Android and Java, and I want to move scroll of ScrollView after a user presses the button for next action (IME_ACTION_SEND). My codes are as follows.
activity_add.xml
It basically consists of TextView, EditText, NumberPicker, Spinner, Button. I want to move the scroll after IME_ACTION_SEND on EditText, so that the NumberPicker is centered on the screen.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/addActivity_scrollview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="15dp">
<LinearLayout
android:id="#+id/layout_activity_add"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/title_addItem"
android:id="#+id/textView"
android:layout_gravity="center_horizontal"
android:textSize="40sp" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:id="#+id/formLayout"
android:layout_marginTop="50dp">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/title_editText"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:hint="#string/hint_title"
android:singleLine = "true"
android:maxLength="20" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:id="#+id/formLayout3"
android:layout_marginTop="50dp">
<TextView
android:id="#+id/period_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/label_period"
android:layout_centerHorizontal="true" />
<NumberPicker
android:id="#+id/period_number_picker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/period_textView"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true">
</NumberPicker>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:id="#+id/formLayout4"
android:layout_marginTop="25dp"
android:layout_marginBottom="25dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/label_category"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_centerInParent="true"
android:layout_toStartOf="#+id/background_spinner"
android:layout_toLeftOf="#+id/background_spinner" />
<Spinner
android:id="#+id/background_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerInParent="true"
android:layout_gravity="center_vertical">
</Spinner>
</RelativeLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/button_submit"
android:layout_gravity="center_horizontal"
android:text="#string/label_submit" />
</LinearLayout>
</ScrollView>
AddItemActivity.java
I've just copied the part which I think is relevant.
public class AddSinceItemActivity extends ActionBarActivity {
EditText title;
Spinner spinner;
NumberPicker numberPicker;
String title_string;
ViewGroup linearLayout;
ScrollView addActivity_scrollview;
#Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add);
addActivity_scrollview = (ScrollView) findViewById(R.id.addActivity_scrollview);
linearLayout = (ViewGroup) findViewById(R.id.layout_activity_add);
title = (EditText) findViewById(R.id.title_editText);
numberPicker = (NumberPicker) findViewById(R.id.period_number_picker);
spinner = (Spinner) findViewById(R.id.background_spinner);
/* For title */
title.setOnEditorActionListener(new TextView.OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEND) {
// I think here is the most important part.
addActivity_scrollview.smoothScrollTo(0, numberPicker.getBottom());
}
return false;
}
});
}
}
For addActivity_scrollview.smoothScrollTo(0, numberPicker.getBottom());,
I've tried many possible codes, such as
addActivity_scrollview.smoothScrollTo(0, spinner.getTop());
addActivity_scrollview.smoothScrollTo(0, 300); (300 is just a random number)
addActivity_scrollview.smoothScrollBy(0, 300);
but the scroll is always stuck (it moves a little but it's always the same position with above codes) and the screen barely shows the selected number of NumberPicker. How can I achieve the goal to set scroll so that the screen shows the entire NumberPicker?
just add this line to your edittext code in xml :android:imeOptions="actionSend" and then just try this into your activityaddActivity_scrollview.smoothScrollTo(0, 480);
I should've added android:imeOptions="actionSend" to <EditText> in order to properly listen on onEditorAction(). I thought it'd be okay with android:singLine="true" because that option enabled "next" action on keyboard.
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/title_editText"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:hint="#string/hint_title"
android:singleLine="true"
android:maxLength="20"
android:imeOptions="actionSend" />
I've created what I want in xml but I need to do it programatically and I can't get it to work. It's a table layout with one row. In that row there is two more table layouts. The first of which has one row containing a picture and the second table layout has two rows containing two textviews and a picture. Is there some kind of xml to java converter? I've tried to write the code now for a couple of hours and can't get the layouts to work. I'd post a picture but I need 10 rep points first. The whole xml file is in a linear layout if it helps.
<TableLayout
android:id="#+id/tablemain"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:gravity="center_horizontal" >
<TableRow
android:id="#+id/TableRow1"
android:background="#drawable/border"
android:weightSum="100" >
<TableLayout
android:id="#+id/Tableout2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="0"
android:background="#drawable/border"
android:gravity="center_horizontal" >
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/imageView1"
android:adjustViewBounds="true"
android:maxHeight="100dp"
android:maxWidth="100dp"
android:padding="3dp"
android:src="#drawable/unknown" />
</TableRow>
</TableLayout>
<TableLayout
android:id="#+id/Tableout3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="100"
android:gravity="center_horizontal"
android:weightSum="100" >
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="50"
android:background="#drawable/border" >
<TextView
android:id="#+id/Judgename"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:padding="7dp"
android:text="Name"
android:textSize="20sp"
android:textStyle="bold" />
</TableRow>
<TableRow
android:id="#+id/tablerowctroom"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="50"
android:background="#drawable/border"
android:weightSum="100" >
<TextView
android:id="#+id/Courtroom"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="70"
android:padding="7dp"
android:text="Room"
android:textSize="15sp"
android:textStyle="bold" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center_vertical"
android:layout_marginRight="10dp"
android:layout_weight="30"
android:src="#drawable/umid" />
</TableRow>
</TableLayout>
</TableRow>
</TableLayout>
This is the new code I'm trying to use based on Nathan Walter's advice. However, It'll set the first set text but the rest are just the default value. Although the layout looks right. How can I set the textfields for each individual view when the method is called.
public void Display(String name, String ctroom) {
ViewGroup parent = (ViewGroup) findViewById(R.id.container);
view = LayoutInflater.from(this).inflate(R.layout.tablebutton, null);
parent.addView(view);
TextView jn = (TextView) findViewById(R.id.JudgenameCourts);
jn.setText(name);
TextView ct = (TextView) findViewById(R.id.Courtroomnew);
ct.setText(ctroom);
view = LayoutInflater.from(this).inflate(R.layout.tablebutton, null);
parent.addView(view);
jn.setText("Name1");
ct.setText("Courtroom1");
}
I think the code you want looks something like this. Let me know if it makes sense.
// Create an array of things to create views from.
// You will probably be getting your array from somewhere else
YourObjectHere[] things = new YourObjectHere[2];
things[0] = new YourObjectHere();
things[1] = new YourObjectHere();
// Get a reference to a LinearLayout to hold your views
LinearLayout list = (LinearLayout) findViewById(R.id.list);
// Loop through your list of objects
for(int i = 0; i < things.length; i++) {
// Inflate an instance of your layout
View listItem = getLayoutInflater().inflate(R.layout.child, null);
// Set the TextViews to the appropriate things
((TextView) listItem.findViewById(R.id.name)).setText(things[i].getName());
((TextView) listItem.findViewById(R.id.type)).setText(things[i].getType());
// Add the inflated view to the list
item.addView(child);
}
I'm trying to follow the official Android guide for CABforListView very closely, but I have not been able to activate context action view on my ListView item long press.
public class MainActivity extends ListActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
loadList(); // loads Cursor data and sets list adapter in AsyncTask
ListView listView = getListView();
listView.setLongClickable(true); // no effect
listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
listView.setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() {
// implemention of MultiChoiceModeListener
});
}
// rest of the class
}
The following is my list_row_item.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="?android:attr/activatedBackgroundIndicator"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:longClickable="true"
android:paddingLeft="15dp"
android:paddingRight="10dp"
android:paddingTop="10dp"
android:paddingBottom="10dp" >
<TextView
android:id="#+id/reminder_row_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/reminder_row_interval"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/reminder_row_description"
android:textAppearance="?android:attr/textAppearanceSmall" />
<Switch
android:id="#+id/switch_reminder_row"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/reminder_row_interval"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" />
<TextView
android:id="#+id/reminder_row_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/reminder_row_interval"
android:layout_below="#+id/reminder_row_interval"
android:textAppearance="?android:attr/textAppearanceSmall" />
</RelativeLayout>
And my activity_main.xml:
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</ListView>
I have tried using listView.setOnItemLongClickListener() to start ActionMode manually, but while that has launched contextual action mode I was not able to do multiple selects, and no tutorial/guide has ever needed to do this. I am missing something.
Basically, I want to achieve exactly this effect as seen in Jelly Bean's alarm clock:
Any pointers would be greatly appreciated!
Based on #Luksprog comment, returning true from onCreateActionMode() will fix your problem