list activity onListItemClick does not firing - java

I nedd to click on items in list activity to do something, but its not working
i search for this problem and saw some answers about this such as :
android:focusable="false"
android:clickable="false"
android:focusableInTouchMode="false"
or
android:descendantFocusability="afterDescendants"
android:descendantFocusability="beforeDescendants"
android:descendantFocusability="blocksDescendants"
but those are not worked
this is my listActivity :
public class TrainListActivity extends SherlockListActivity
{
public static String varStart = "com.example.traininfo.startcity";
public static String varDestination = "com.example.traininfo.destinationcity";
private String start;
private String destination;
ArrayList<TrainType> trains;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_trainlist);
Log.i("SearchTrain", "try to get extras...");
start = getIntent().getExtras().getString(varStart);
destination = getIntent().getExtras().getString(varDestination);
TrainController tc = new TrainController(this);
trains = new ArrayList<TrainType>();
trains = tc.getTrainList(start, destination).getTrain();
Log.i("SearchTrain", "got the train list...");
TrainListAdapter adapter = new TrainListAdapter(this, trains);
Log.i("SearchTrain", "adapter initialized successfully!!");
setListAdapter(adapter);
}
#Override
protected void onListItemClick(ListView l, View v, int position, long id)
{
// I want to do something here :(
super.onListItemClick(l, v, position, id);
Log.i("trainList", "on click");
}
}
row xml file :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#27ae60"
android:paddingBottom="5dp"
android:focusable="true"
android:focusableInTouchMode="true"
android:clickable="true" >
<TextView
android:id="#+id/tvTrainName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:gravity="center"
android:text="#string/resultTrainName"
android:textColor="#android:color/white"
android:textSize="20sp"
android:focusable="false"
android:clickable="false"
android:focusableInTouchMode="false"
android:textStyle="bold" />
<TextView
android:id="#+id/tvStartLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#id/tvTrainName"
android:gravity="right"
android:text="#string/resultTimeOut"
android:focusable="false"
android:clickable="false"
android:focusableInTouchMode="false"
android:textColor="#android:color/white"
android:textSize="15sp" />
<TextView
android:id="#+id/tvTimeOut"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/tvTrainName"
android:layout_marginRight="30sp"
android:layout_toLeftOf="#id/tvStartLabel"
android:text="#string/resultTimeOutEx"
android:focusable="false"
android:clickable="false"
android:focusableInTouchMode="false"
android:textColor="#android:color/white"
android:textSize="15sp" />
<TextView
android:id="#+id/tvFinishLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#id/tvStartLabel"
android:gravity="right"
android:focusable="false"
android:clickable="false"
android:focusableInTouchMode="false"
android:text="#string/resultTimeIn"
android:textColor="#android:color/white"
android:textSize="15sp" />
<TextView
android:id="#+id/tvTimeIn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/tvTimeOut"
android:layout_below="#id/tvTimeOut"
android:text="#string/resultTimeInEx"
android:focusable="false"
android:clickable="false"
android:focusableInTouchMode="false"
android:textColor="#android:color/white"
android:textSize="15sp" />
<TextView
android:id="#+id/tvPrices"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#id/tvTimeIn"
android:gravity="right"
android:focusable="false"
android:focusableInTouchMode="false"
android:clickable="false"
android:textColor="#android:color/white"
android:textSize="15sp" />
<ImageButton
android:id="#+id/btnMoreInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="23dp"
android:focusable="false"
android:clickable="false"
android:focusableInTouchMode="false"
android:background="#android:color/transparent"
android:contentDescription="#string/resultMoreInfo"
android:src="#drawable/action_info" />
and ListActivity xml File :
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:drawSelectorOnTop="false"
android:clickable="true"
android:descendantFocusability="afterDescendants" />
</LinearLayout>
please help me :(

Use normal activity and put a ListView in xml. Use inflator to use your custom row design. Just put the focusable=false for your imagebutton. It will allow you to click on the row and you can apply a separate click listener for your imagebutton to handle its click separately.

I faced the same problem not too long ago. It seems that the ImageButton takes focus regardless what you do. What I did was to replace the ImageButton with and ImageView and set the listener to it.
This is how your xml files should look like.
row xml file :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#27ae60"
android:paddingBottom="5dp" >
<TextView
android:id="#+id/tvTrainName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:gravity="center"
android:text="#string/resultTrainName"
android:textColor="#android:color/white"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="#+id/tvStartLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#id/tvTrainName"
android:gravity="right"
android:text="#string/resultTimeOut"
android:textColor="#android:color/white"
android:textSize="15sp" />
<TextView
android:id="#+id/tvTimeOut"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/tvTrainName"
android:layout_marginRight="30sp"
android:layout_toLeftOf="#id/tvStartLabel"
android:text="#string/resultTimeOutEx"
android:textColor="#android:color/white"
android:textSize="15sp" />
<TextView
android:id="#+id/tvFinishLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#id/tvStartLabel"
android:gravity="right"
android:text="#string/resultTimeIn"
android:textColor="#android:color/white"
android:textSize="15sp" />
<TextView
android:id="#+id/tvTimeIn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/tvTimeOut"
android:layout_below="#id/tvTimeOut"
android:text="#string/resultTimeInEx"
android:textColor="#android:color/white"
android:textSize="15sp" />
<TextView
android:id="#+id/tvPrices"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#id/tvTimeIn"
android:gravity="right"
android:textColor="#android:color/white"
android:textSize="15sp" />
<ImageView
android:id="#+id/btnMoreInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="23dp"
android:background="#android:color/transparent"
android:contentDescription="#string/resultMoreInfo"
android:src="#drawable/action_info" />
Activity xml.
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:drawSelectorOnTop="false"/>
</LinearLayout>

Related

Android - How do I expand the height of a view from bottom to top?

I'm trying to make a visualization of some data in Android using a vertical bar chart, but when I increase or decrease the height of a View programatically by clicking a button, it changes from top to bottom, as in the image below (default value is 300).
How do I change the height from bottom to top, ie keeping the base of the view fixed?
Expected result:
My code in Java:
public final class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.activity_main);
}
#Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
LinearLayout layoutXAxis = (LinearLayout)this.findViewById(R.id.layoutX);
LinearLayout layoutYAxis = (LinearLayout)this.findViewById(R.id.layoutY);
LinearLayout layoutZAxis = (LinearLayout)this.findViewById(R.id.layoutZ);
TextView txtXAxis = (TextView)layoutXAxis.findViewById(R.id.txtXAxis);
TextView txtYAxis = (TextView)layoutYAxis.findViewById(R.id.txtYAxis);
TextView txtZAxis = (TextView)layoutZAxis.findViewById(R.id.txtZAxis);
View graphXAxis = (View)layoutXAxis.findViewById(R.id.XAxis);
View graphYAxis = (View)layoutYAxis.findViewById(R.id.YAxis);
View graphZAxis = (View)layoutZAxis.findViewById(R.id.ZAxis);
LinearLayout layoutBtnAdd = (LinearLayout)this.findViewById(R.id.layAdd);
Button btnAddX = (Button)layoutBtnAdd.findViewById(R.id.btnXAdd);
Button btnAddY = (Button)layoutBtnAdd.findViewById(R.id.btnYAdd);
Button btnAddZ = (Button)layoutBtnAdd.findViewById(R.id.btnZAdd);
LinearLayout layoutBtnSub = (LinearLayout)this.findViewById(R.id.laySub);
Button btnSubX = (Button)layoutBtnSub.findViewById(R.id.btnXSub);
Button btnSubY = (Button)layoutBtnSub.findViewById(R.id.btnYSub);
Button btnSubZ = (Button)layoutBtnSub.findViewById(R.id.btnZSub);
txtXAxis.setText(String.valueOf(graphXAxis.getLayoutParams().height));
txtYAxis.setText(String.valueOf(graphYAxis.getLayoutParams().height));
txtZAxis.setText(String.valueOf(graphZAxis.getLayoutParams().height));
btnAddX.setOnClickListener((OnClickListener)(new OnClickListener() {
public final void onClick(View it) {
View graph = graphXAxis;
LayoutParams params = graph.getLayoutParams();
params.height += 10;
graph = graphXAxis;
graph.setLayoutParams(params);
TextView text = txtXAxis;
View graph = graphXAxis;
text.setText(String.valueOf(graph.getLayoutParams().height));
}
}));
... // onClickListener of the other buttons
}
My code in XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context=".MainActivity">
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:id="#+id/layoutY">
<TextView
android:id="#+id/txtYAxis"
android:layout_gravity="center"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textAlignment="center"
android:text="Y AXIS"
android:textStyle="bold"
android:textSize="18sp"
android:textColor="#android:color/holo_blue_light"/>
...
<View android:id="#+id/YAxis"
android:layout_width="75dp"
android:layout_height="200dp"
android:background="#android:color/holo_blue_dark"/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/layoutX"
android:layout_toLeftOf="#id/layoutY"
android:layout_toStartOf="#id/layoutY"
android:layout_marginRight="50dp"
android:layout_marginEnd="50dp">
<TextView
android:id="#+id/txtXAxis"
android:layout_gravity="center"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textAlignment="center"
android:text="X AXIS"
android:textStyle="bold"
android:textSize="18sp"
android:textColor="#android:color/holo_red_light"/>
...
<View android:id="#+id/XAxis"
android:layout_width="75dp"
android:layout_height="200dp"
android:background="#android:color/holo_red_dark"/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/layoutZ"
android:layout_toRightOf="#id/layoutY"
android:layout_toEndOf="#id/layoutY"
android:layout_marginLeft="50dp"
android:layout_marginStart="50dp">
<TextView
android:id="#+id/txtZAxis"
android:layout_gravity="center"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textAlignment="center"
android:text="Z AXIS"
android:textStyle="bold"
android:textSize="18sp"
android:textColor="#android:color/holo_green_light"/>
...
<View android:id="#+id/ZAxis"
android:layout_width="75dp"
android:layout_height="200dp"
android:background="#android:color/holo_green_dark"/>
</LinearLayout>
...
</RelativeLayout>
You might consider constructing your layout like the following.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/button_layout"
android:orientation="horizontal">
<LinearLayout
android:id="#+id/layoutY"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="#+id/txtYAxis"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="Y AXIS"
android:textColor="#android:color/holo_blue_light"
android:textSize="18sp"
android:textStyle="bold" />
<View
android:id="#+id/YAxis"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:background="#android:color/holo_blue_dark"
android:gravity="center_horizontal" />
</LinearLayout>
<LinearLayout
android:id="#+id/layoutX"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|bottom"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="#+id/txtXAxis"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="X AXIS"
android:textAlignment="center"
android:textColor="#android:color/holo_red_light"
android:textSize="18sp"
android:textStyle="bold" />
<View
android:id="#+id/XAxis"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:background="#android:color/holo_red_dark" />
</LinearLayout>
<LinearLayout
android:id="#+id/layoutZ"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|bottom"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="#+id/txtZAxis"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Z AXIS"
android:textAlignment="center"
android:textColor="#android:color/holo_green_light"
android:textSize="18sp"
android:textStyle="bold" />
<View
android:id="#+id/ZAxis"
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:background="#android:color/holo_green_dark" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/button_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<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>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<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>
</LinearLayout>
</RelativeLayout>
Here is the output.
Hope that helps!

For a view with rotation perform(click()) doesn't work in espresso ui test

I write an espresso UI test for my application, and for some views (in this case ImageButton) perform(click()) doesn't work and also no error is displayed.
this is the line that not worked:
try {
Thread.sleep(TIME_NORMAL_ELPASED);
} catch (InterruptedException e) {
e.printStackTrace();
}
onView(allOf(withId(R.id.toolbar_navigation_btn)
, isCompletelyDisplayed())).perform(click());
and this is my 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="activities.DepartFlight.fragments.AvailableFragment">
<android.support.v7.widget.Toolbar
android:id="#+id/available_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_alignParentTop="true"
android:background="#drawable/background_toolbar">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageButton
android:id="#+id/toolbar_navigation_btn"
android:layout_width="#dimen/icon_toolbar"
android:layout_height="#dimen/icon_toolbar"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:background="#drawable/button_selector"
android:rotation="180"
android:src="#drawable/ic_back"
android:tint="#color/white" />
<com.faranegar.bookflight.customView.CustomTextView
android:id="#+id/text_toolbar_flight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="2dp"
android:textColor="#color/white" />
<com.faranegar.bookflight.customView.CustomTextView
android:id="#+id/toolbar_subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/text_toolbar_flight"
android:layout_centerHorizontal="true"
android:textColor="#color/white"
android:textSize="#dimen/font_size" />
</RelativeLayout>
</android.support.v7.widget.Toolbar>
<include
android:id="#+id/zero_filtered_items"
android:visibility="gone"
layout="#layout/zero_filterd_itesm_row" />
<com.faranegar.bookflight.customView.CustomRecyclerView
android:id="#+id/available_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/depart_flight_activity_footer"
android:layout_below="#id/available_toolbar"
android:background="#android:color/transparent"
android:visibility="gone"
/>
<com.tuyenmonkey.mkloader.MKLoader
android:id="#+id/progressBar"
android:layout_width="55dp"
android:layout_height="55dp"
android:layout_centerInParent="true"
android:visibility="gone"
app:mk_color="#color/colorPrimary"
app:mk_type="TwinFishesSpinner" />
<RelativeLayout
android:id="#+id/depart_flight_activity_footer"
android:layout_width="match_parent"
android:layout_height="44dp"
android:layout_alignParentBottom="true"
android:background="#color/colorPrimary"
android:visibility="visible">
<LinearLayout
android:id="#+id/view_sort"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="18dp"
android:layout_marginStart="18dp"
android:gravity="center"
android:orientation="horizontal">
<ImageView
android:layout_width="15dp"
android:layout_height="15dp"
android:src="#drawable/sort_icon"
android:tint="#color/white" />
<com.faranegar.bookflight.customView.CustomTextView
android:id="#+id/sortText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:text="#string/sort_text"
android:textColor="#color/white"
android:textSize="#dimen/text_less_normal" />
</LinearLayout>
<LinearLayout
android:id="#+id/view_filter"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="18dp"
android:layout_toRightOf="#id/view_sort"
android:gravity="center"
android:orientation="horizontal"
android:visibility="visible">
<ImageView
android:layout_width="15dp"
android:layout_height="15dp"
android:src="#drawable/ic_filter"
android:tint="#color/white" />
<com.faranegar.bookflight.customView.CustomTextView
android:id="#+id/filterText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:text="#string/filter_text"
android:textColor="#color/white"
android:textSize="#dimen/text_less_normal" />
</LinearLayout>
<RelativeLayout
android:id="#+id/next_day"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="#+id/back_day">
<Button
android:id="#+id/next_day_available_btn"
android:layout_width="20dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:background="#drawable/button_selector"
android:textColor="#color/white"
android:textSize="#dimen/icon_btn" />
<com.faranegar.bookflight.customView.CustomTextView
android:id="#+id/next_day_available_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#id/next_day_available_btn"
android:text="#string/next_day"
android:textColor="#color/white"
android:visibility="visible" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/back_day"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginLeft="15dp"
android:layout_marginStart="15dp">
<Button
android:id="#+id/prev_day_available_btn"
android:layout_width="20dp"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/prev_day_available_text"
android:background="#drawable/button_selector"
android:textColor="#color/white"
android:textSize="#dimen/icon_btn" />
<com.faranegar.bookflight.customView.CustomTextView
android:id="#+id/prev_day_available_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="#string/back_day"
android:textColor="#color/white" />
</RelativeLayout>
</RelativeLayout>
<com.faranegar.bookflight.customView.CustomTextView
android:id="#+id/warning"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="#string/not_available_flights"
android:textColor="#android:color/black"
android:textSize="16sp"
android:visibility="gone" />
<com.faranegar.bookflight.customView.CustomTextView
android:id="#+id/ads_motto_captan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/progressBar"
android:layout_centerInParent="true"
android:padding="15dp"
android:text="#string/captan_ads_motto"
android:textColor="#color/colorPrimary"
android:textSize="16sp"
android:visibility="gone" />
<WebView
android:id="#+id/arzanBelitBanner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/depart_flight_activity_footer"
android:visibility="gone" />
<include
android:id="#+id/failedLayout"
layout="#layout/failed_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:visibility="gone"
/>
<include
android:id="#+id/saatraapProgressBarLayout"
layout="#layout/saatraap_brogressbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:visibility="gone" />
and a fragment shows the above XML.
what's wrong?
I think setRotation may have confused click() and coordinates calculation. If that's the case, you could either remove android:rotation then rotate the image physically, or try to create a custom click action:
public static ViewAction forceClick() {
return new ViewAction() {
#Override public Matcher<View> getConstraints() {
return allOf(isClickable(), isEnabled());
}
#Override public String getDescription() {
return "force click";
}
#Override public void perform(UiController uiController, View view) {
view.performClick();
uiController.loopMainThreadUntilIdle();
}
};
}
This action performs click on the view by invoking performClick() without finding its coordinates. But make sure the view has the click listener attached in the app:
onView(withId(R.id.toolbar_navigation_btn)).perform(forceClick());
If there's no error then it's safe to assume that the click was successful. Try enabling the "Show taps" Developer option to see exactly where the click occurs.

How to set list view height programatically in android

I am making an application in which my keyboard comes up on the activity and it hides may header view (layout) I have searched and tried adjust pane state hidden,adjust nothing all the attributes in manifest but nothing solved my problem then I found one the posts over stackover flow that you can calculate the spacing then set the height I implemented but the behaviour is still same this is the sanpshot when activity comes
but when keyborad pops up it hides my header view this is snapshot of what's happening
this is my manifest code
<activity
android:name="com.dd.sproutchat.ChatActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustNothing">
</activity>
this is my layout of that activity
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/main">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffff">
<RelativeLayout
android:id="#+id/TopLayout"
android:layout_width="match_parent"
android:layout_height="55dp">
<ImageButton
android:id="#+id/btn_back"
android:layout_width="20dp"
android:layout_height="30dp"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:background="#drawable/back_icon_2x"
android:textColor="#000000"
android:textSize="22sp" />
<LinearLayout
android:id="#+id/Image"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_centerVertical="true"
android:layout_marginLeft="15dp"
android:layout_toRightOf="#+id/btn_back">
<Button
android:id="#+id/recUserImg"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="#drawable/image_circle_shape"
android:text=""
android:textColor="#color/white"
android:visibility="gone" />
<com.dd.sproutchat.customcontrols.MLRoundedImageView
android:id="#+id/userImg"
android:layout_width="50dp"
android:layout_height="50dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_toLeftOf="#+id/btn_Search"
android:layout_toRightOf="#+id/Image"
android:orientation="vertical">
<TextView
android:id="#+id/txtUserName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="start"
android:gravity="left"
android:singleLine="true"
android:text=""
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#android:color/black" />
<TextView
android:id="#+id/txtOnlineStatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:singleLine="true"
android:text=""
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#android:color/black" />
</LinearLayout>
<ImageButton
android:id="#+id/btn_Menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:background="#drawable/menu_icon_2x"
android:visibility="gone" />
<ImageButton
android:id="#+id/btn_Search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:background="#drawable/search_icon_2x" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/Rl_line"
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_below="#+id/TopLayout"
android:background="#color/chat_border"></RelativeLayout>
<RelativeLayout
android:id="#+id/Rl_Options"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_below="#+id/Rl_line"
android:background="#color/chat_options_bg">
<ImageButton
android:id="#+id/btn_Home"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="20dp"
android:background="#drawable/home_btn_active_2x" />
<ImageButton
android:id="#+id/btn_SproutesList"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="#drawable/chat_btn_2x" />
<ImageButton
android:id="#+id/btn_Note"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="20dp"
android:background="#drawable/note_btn_2x" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/Rl_line2"
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_below="#+id/Rl_Options"
android:background="#color/chat_border"></RelativeLayout>
<RelativeLayout
android:id="#+id/Rl_ChatLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/Rl_MessageLayout"
android:layout_below="#+id/Rl_line2">
<!-- android:background="#drawable/chat_bg_2x" -->
<RelativeLayout
android:id="#+id/Btn_Chats"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:orientation="horizontal"
android:weightSum="4">
<RelativeLayout
android:id="#+id/count"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone">
<ImageButton
android:id="#+id/btn_Sortby"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="10dp"
android:background="#drawable/icon_sortby_sprout_2x" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_toLeftOf="#+id/btn_AddSprout"
android:layout_toRightOf="#+id/btn_Sortby"
android:weightSum="2">
<Button
android:id="#+id/btn_AllSprouts"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/btn_blue"
android:paddingBottom="3dp"
android:paddingLeft="25dp"
android:paddingRight="25dp"
android:paddingTop="3dp"
android:text="#string/AllSprouts"
android:textColor="#color/white" />
<Button
android:id="#+id/btn_AllFavorites"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_weight="1"
android:background="#drawable/btn_blank"
android:paddingBottom="3dp"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:paddingTop="3dp"
android:text="#string/AllFavorites"
android:textColor="#color/grey_start" />
</LinearLayout>
<ImageButton
android:id="#+id/btn_AddSprout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:background="#drawable/icon_add_sprout_2x" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/noteLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:paddingBottom="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:visibility="gone">
<EditText
android:id="#+id/searchBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#+id/imageButton4" />
<ImageButton
android:id="#+id/imageButton4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_toLeftOf="#+id/imageButton5"
android:background="#drawable/sort" />
<ImageButton
android:id="#+id/imageButton5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginLeft="10dp"
android:background="#drawable/add" />
</RelativeLayout>
</RelativeLayout>
<ListView
android:id="#+id/Lv_Chat"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/Btn_Chats"
android:layout_above="#+id/Rl_MessageLayout"
android:divider="#null"
android:dividerHeight="0dp"
android:paddingBottom="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp"
android:scrollbars="none"
android:stackFromBottom="true"
android:transcriptMode="normal"></ListView>
<RelativeLayout
android:id="#+id/Rl_MessageLayout"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:background="#color/chat_screen_bottom">
<ImageButton
android:id="#+id/btn_Attachment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:background="#drawable/attachment_icon_white_2x" />
<EditText
android:id="#+id/edt_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_toLeftOf="#+id/btn_Send"
android:layout_toRightOf="#+id/btn_Attachment"
android:background="#drawable/txt_field"
android:imeOptions="actionDone"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:singleLine="true"
/>
<ImageButton
android:id="#+id/btn_Send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:background="#drawable/icon_send_white_2x" />
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
and this is my activity code for calculating height of listview
private static boolean keyboardHidden = true;
private static int reduceHeight =0;
final View decorView = this.getWindow().getDecorView();
decorView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
#Override
public void onGlobalLayout() {
Rect rect = new Rect();
decorView.getWindowVisibleDisplayFrame(rect);
int displayHeight = rect.bottom - rect.top;
int height = decorView.getHeight();
boolean keyboardHiddenTemp = (double) displayHeight / height > 0.8;
int mylistviewHeight = Lv_Chat.getMeasuredHeight();
if (keyboardHiddenTemp != keyboardHidden) {
keyboardHidden = keyboardHiddenTemp;
if (!keyboardHidden) {
reduceHeight = height - displayHeight;
RelativeLayout.LayoutParams mParam = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, mylistviewHeight - reduceHeight);
Lv_Chat.setLayoutParams(mParam);
Lv_Chat.requestLayout();
} else {
RelativeLayout.LayoutParams mParam = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, mylistviewHeight + reduceHeight);
Lv_Chat.setLayoutParams(mParam);
Lv_Chat.requestLayout();
}
}
}
});
I have also tried this link for setting xml file
http://codetheory.in/android-add-views-view-groups-listview-gridview/
any help please
To change the height of ListView you should use LayoutParams:
ViewGroup.LayoutParams param = listView.getLayoutParams();
param.height = anynumberhere;
listView.setLayoutParams(param);
listView.requestLayout();
According to your question, this is the way to change the ListView's height, but i don't think its the rite approach to make that header of yours stay in its place.
I think you should use adjustResize instead of adjustNothing and add android:fitsSystemWindows="true" in your root RelativeLayout instead of programmatically trying to resize your views.

ListView with custom adapter is not selectable

I have ListView with custom adapter. Listview is not clickable but setOnItemLongClickListener worked properly. ListView row.xml is below:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1" >
<ImageView
android:id="#+id/ivTourImage"
android:layout_width="120dp"
android:layout_height="match_parent" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="1">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="horizontal"
android:weightSum="1">
<TextView
android:id="#+id/lblTourName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="Tour Name" />
<RatingBar
android:id="#+id/ratingBarTourStarCount"
style="#style/hotelRatingBarSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:focusable="false"
android:isIndicator="true"
android:numStars="5"
android:stepSize="1.0" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="horizontal"
android:weightSum="1">
<TextView
android:id="#+id/lblPlace"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="Place" />
<TextView
android:id="#+id/lblPrice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="#b6fffa12"
android:text="Price"
android:textColor="#ff4770ff" />
</RelativeLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="horizontal"
android:weightSum="1">
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="16dp"
android:src="#drawable/adult_icon_16x16" />
<TextView
android:id="#+id/lblAdultCount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Adult" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="16dp"
android:layout_marginLeft="15dp"
android:src="#drawable/children_icon_16x16" />
<TextView
android:id="#+id/lblChildCount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Child" />
<ImageView
android:id="#+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="16dp"
android:layout_marginLeft="15dp"
android:src="#drawable/meal_icon_16x16" />
<TextView
android:id="#+id/lblMealCount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Meal" />
</LinearLayout>
</LinearLayout>
ListView usage:
<LinearLayout
android:id="#+id/tabTourList"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/listViewTourAnounce"
android:layout_gravity="center"/>
</LinearLayout>
How to make my listview clickable? Please help me
Try by this code It may Help you.
ListView roomsList
List<String> roomlistdata;
roomlistdata = new ArrayList<String>();
roomsList = (ListView) findViewById(R.id.roomsList);
roomlistdata.add("your data");
ArrayAdapter<String> str = new ArrayAdapter<String>(
getBaseContext(),
android.R.layout.simple_list_item_1,
roomlistdata);
roomsList.setAdapter(str);
listView.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position,long arg3) {
view.setSelected(true);
String UserSelected = ((TextView) view).getText().toString();
...//contests_listView is a array list
}
}

How to make the popup window BG blur

In my app I am using popup window it looks like this, But the background for the popup window is not blur, how do I make it appear blur.
Here is the code,
View v1 = inflatter.inflate(R.layout.problemlistmenu_popup, null);
v1.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
int height1 = v1.getMeasuredHeight();
clickOnProblemName = new PopupWindow(showProblemMenu(details), (int) (width * 0.8), height1, true);
clickOnProblemName.showAtLocation(mainlayout, Gravity.CENTER, 0, 0);
showProblemMenu
protected View showProblemMenu(String details) {
View v = null;
v = inflatter.inflate(R.layout.problemlistmenu_popup, null);
return v;
}
And here is the xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mainlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/silver002"
android:orientation="vertical" >
<FrameLayout
android:layout_width="match_parent"
android:layout_height="30dp"
android:background="#drawable/headerstyle1" >
<TextView
android:id="#+id/tvHeaderText"
android:layout_width="match_parent"
android:layout_height="30dp"
android:gravity="left|center_vertical"
android:paddingLeft="5dp"
android:text=""
android:textColor="#android:color/white"
android:textSize="12dp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="30dp"
android:layout_marginTop="4dp"
android:gravity="right|center_vertical" >
<TextView
android:id="#+id/tvCancel"
android:layout_marginRight="3dp"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:paddingLeft="4dp"
android:paddingRight="4dp"
android:layout_marginTop="2dp"
android:background="#drawable/backgroundstyle_btn1"
android:layout_gravity="right"
android:text="Cancel"
android:gravity="center"
android:textColor="#android:color/white"
android:textSize="14dp"
android:textStyle="bold" />
</LinearLayout>
</FrameLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:padding="5dp"
android:orientation="vertical" >
<TextView
android:id="#+id/tvChronic"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:padding="10dp"
android:textColor="#android:color/black"
android:text=""
android:textStyle="bold"
android:background="#drawable/row_selector"
android:textSize="14dp" />
<TextView
android:id="#+id/tvResolved"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:padding="10dp"
android:text="Change to Resolved"
android:textStyle="bold"
android:background="#drawable/row_selector_alternative"
android:textColor="#android:color/black"
android:textSize="14dp" />
<TextView
android:id="#+id/tvProblemName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:padding="10dp"
android:text="Edit Problem Name"
android:textStyle="bold"
android:background="#drawable/row_selector"
android:textColor="#android:color/black"
android:textSize="14dp" />
<TextView
android:id="#+id/tvComments"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:padding="10dp"
android:text="Edit Comments"
android:textStyle="bold"
android:background="#drawable/row_selector_alternative"
android:textColor="#android:color/black"
android:textSize="14dp" />
</LinearLayout>
</ScrollView>
</LinearLayout>
Thanks in advance.
There is a really good tutorial here that shows you how to do this:
http://www.stealthcopter.com/blog/2010/01/android-blurring-and-dimming-background-windows-from-dialogs/
May this help
mPopupWindow.setTouchable(true);
mPopupWindow.setFocusable(false);
mPopupWindow.setOutsideTouchable(false);

Categories