jeudi 28 mai 2015

How can we use two listview of Checkboxes in Android

I have an application. On the result page there is a button. By clicking the button I want to show a filter option to the users so that they can filter the data !

SampleImage

I am not able to create this layout ,what i have to use for this to create the layout

Please help me with this

App crashes when loading image from gallery

In my app ,i have two buttons ,one for loading the image from gallery(from device )and another one for taking pictures by accesing the camera of the device,My code is working properly on some devices ,bt in some devices ,the app crashes when clicking an image in the gallery.Can anybody help me to find out the actual propblem??

public class MainActivity extends ActionBarActivity {
private static int RESULT_LOAD_IMAGE = 1;
private static final int CAMERA_REQUEST = 1888;
private ImageView imageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Button buttonLoadImage = (Button) findViewById(R.id.buttonLoadPicture);
    buttonLoadImage.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {

            Intent i = new Intent(
                    Intent.ACTION_PICK,
                    android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);

            startActivityForResult(i, RESULT_LOAD_IMAGE);
        }
    });
    this.imageView = (ImageView)this.findViewById(R.id.imgView);
    Button photoButton = (Button) this.findViewById(R.id.button2);
    photoButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
            startActivityForResult(cameraIntent, CAMERA_REQUEST);
        }
    });
}

And the xml is

<LinearLayout xmlns:android="http://ift.tt/nIICcg" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent">
<ImageView android:id="@+id/imgView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1"></ImageView>
<RelativeLayout
    android:id="@+id/relativeLayout1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@android:color/black" >
<Button android:id="@+id/buttonLoadPicture"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"

    android:layout_weight="0"
    android:text="Load Picture"
    android:layout_gravity="center"></Button>
    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Take Picture"
        android:layout_alignParentRight="true"/>

</RelativeLayout>

how to share ideas, code, suggestion in our stackoverflow

I have some useful information i want to share these information, ideas, code, suggestion, and information in our stackoverflow website for programmer to get a lot of help.

like this

Hi Every one I want to share with you people a

special android API Demo code/Project, you would be like my post :), i posted All android API demo you can get a lot of help from this code, It contains more than 1000 of tasks,

The API Demos application includes a variety of small applications that illustrate the use of various Android APIs. It includes samples of

  • Activities
  • Graphic
  • Hardware Related
  • Animations
  • Notifications
  • Alarms
  • Progress Dialogs
  • Intents
  • Menus
  • Search
  • Persistent application state
  • Preferences
  • Background Services
  • App Widgets
  • Voice Recognition
  • Text to Voice
  • And many many more...

Download Source Code for All Android API Demo

how to set time using progress bar in android

I want to create the Dialog with progress bar to show the hours and mins like shown below, is anyone able to help me?

What I want

How to show warning/error if used resource id belongs to another activity layout

Is there a way to show some warning/error when Android resource id does not belong to layout inflated in Activity?

Following is simple example, but in more complex layouts it is much harder to track down such issues as they can only be found during run-time. I would like to be able to catch them at compile-time.

MainActivity initialization

protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    // how to prevent erroneous usage of R.id.text2 at compile time
    TextView t = (TextView) findViewById(R.id.text2);
}

activity_main.xml

<RelativeLayout xmlns:android="http://ift.tt/nIICcg"
                xmlns:tools="http://ift.tt/LrGmb4"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                tools:context=".MainActivity">

    <TextView android:id="@+id/text1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

</RelativeLayout>

activity_second.xml

<RelativeLayout xmlns:android="http://ift.tt/nIICcg"
                xmlns:tools="http://ift.tt/LrGmb4"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                tools:context=".SecondActivity">

    <TextView android:id="@+id/text2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

</RelativeLayout>

Android Tablelayout Show diferent columns

Good afternoon,

I'm doing a TableLayout and need to know how to have a column that can have text or an image.

That is, if a selected option need to show a picture in this column, if this option is not selected need to show a text.

This variation is row to row. I can have a row with image at this column and text on next row

Transitioning between two activities using slider in android studio

I am creating a friend finding app in Android Studio 1.1.0 which incorporates the Google Maps API. This does not allow me to create any widgets on my current activity so I would like to create a slider (Similar to Facebook app on IOS) in which data can be displayed.

Any help will be appreciated.

how to open a pdf from sdcard and display in fragment android

I am implementing a tablet application which at left side shows list of my pdf files and on the right side I want to show the pdf file data. How can I do that? and I want to open Pdf in fragment. Requirements: - Must be able to open PDF using Fragments in Android. - Should load PDF from local file. - User must be able to navigate pdf pages using simple Vertical Scroll. - User must be able to zoom with pinch (finger gesture) - No other controller on the screen. - PDF should cover the all space available

Abnormal Behavior with RadioButton

I am using RadioButton in my layout. Where i have provided background to the RadioButton. Below is the code

<RadioGroup
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="horizontal">

    <RadioButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:button="@null"
        android:background="@drawable/rb_spain"
        android:id="@+id/am_rb_spain" />

    <RadioButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:button="@null"
        android:background="@drawable/rb_germany"
        android:layout_marginLeft="@dimen/margin_15"
        android:layout_marginRight="@dimen/margin_15"
        android:id="@+id/am_rb_german" />

    <RadioButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:button="@null"
        android:background="@drawable/rb_english"
        android:id="@+id/am_rb_english" />

</RadioGroup>

RadioButton background drawable

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://ift.tt/nIICcg" >
    <item android:state_checked="false" android:drawable="@drawable/ic_spain" />
    <item android:state_checked="true" android:drawable="@drawable/ic_spain_pressed" /> //pressed image is Large in size
    <item android:drawable="@drawable/ic_spain" /> <!-- default -->
</selector>

I have saved the selection in TinyDB so that app will remember my selection whenever i open my app. But whenever i open my app the default selected RadioButton background Appears Large. I have taken all the images of same size in drawable's with same padding.

First flag is Default selected here. But it appear to be slightly large in size

First flag is Default selected here

Now i have pressed 2nd flag. But first flag is not coming to its normal state.

Now i have selected 2nd flag

Android LinearLayout static height converting to wrap_content

I am trying to inflate and display a LinearLayout with a specific height but when displayed the height always gets converted to wrap_content. My layout is:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://ift.tt/nIICcg"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="@dimen/dialog_title_height"
    android:padding="@dimen/default_padding"
    android:layout_weight="1">

    <TextView
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:gravity="center_vertical"
        android:text="Scan for devices" />

    <ProgressBar
        android:id="@+id/progressBarScanning"
        android:layout_width="wrap_content"
        android:layout_height="match_parent" />

</LinearLayout>

It seams fine at first but when I set the ProgressBar visibility to View.GONE then the layout height shrinks to the size of the TextView which is much smaller than the set layout_height on the parent layout.

But, if I wrap the views in a 2nd LinearLayout with the specified height and set the parent to wrap_content then it works just fine. Like this:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://ift.tt/nIICcg"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="@dimen/default_padding"
    android:layout_weight="1">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="@dimen/dialog_title_height">

        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center_vertical"
            android:text="Scan for devices" />

        <ProgressBar
            android:id="@+id/progressBarScanning"
            android:layout_width="wrap_content"
            android:layout_height="match_parent" />
    </LinearLayout>

</LinearLayout>

But now of course AndroidStudio complains that the 2nd LinearLayout is useless.

What is the proper way to do this?

How to show data inside the PopupWindow in android?

There are 10 buttons on absolute layout and I want that onClick a popwindow will show and inside the window I want 4 ImageViews and 4 ImageButtons (ImageButtons will used for playing an audio). Kindly help me out. The popup window's orientation will be landscape and align to the right side.

mercredi 27 mai 2015

What should be the best layout elements for this android screen?

I want to achieve this layout screen(attached here-in) in android, i tried with designing the page as per below code, but while testing the screen on device it went horribly slow.

On browsing few links, came to know that it has happened due to excessive nesting of linear layouts, same is reflected in hierarchy viewer.

So I wanted to understand what should be best go here to design this app ?

PS : I am new bie to android world, so want to learned from your expert advise asap.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://ift.tt/nIICcg"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/player_reg_back"
android:orientation="vertical" >

<ImageView
    android:id="@+id/imgView"
    android:layout_width="162dp"
    android:layout_height="170dp"
    android:layout_gravity="center"
    android:layout_marginTop="20dp" />

<Button
    android:id="@+id/button"
    android:layout_width="128dp"
    android:layout_height="33dp"
    android:layout_gravity="center"
    android:layout_marginBottom="15dp"
    android:layout_marginTop="20dp"
    android:paddingTop="5dp"
    android:text="Photo Upload" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/textViewstatus"
        android:layout_width="125dp"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp"
        android:layout_marginLeft="5dp"
        android:text="Profile Status"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <EditText
        android:id="@+id/editTextstatus"
        android:layout_width="152dp"
        android:layout_height="25dp"
        android:layout_marginLeft="30dp"
        android:background="#00000000"
        android:ems="10" >

        <requestFocus />
    </EditText>
</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/textViewcity"
        android:layout_width="125dp"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp"
        android:layout_marginLeft="5dp"
        android:text="City"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <EditText
        android:id="@+id/editTextcity"
        android:layout_width="152dp"
        android:layout_height="25dp"
        android:layout_marginLeft="30dp"
        android:background="#00000000"
        android:ems="10" />
</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/textViewLocation"
        android:layout_width="125dp"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp"
        android:layout_marginLeft="5dp"
        android:text="Location"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <EditText
        android:id="@+id/editTextLocation"
        android:layout_width="152dp"
        android:layout_height="25dp"
        android:layout_marginLeft="30dp"
        android:background="#00000000"
        android:ems="10" />
</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/textViewmobile"
        android:layout_width="125dp"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp"
        android:layout_marginLeft="5dp"
        android:text="Mobile"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <EditText
        android:id="@+id/editTextMobile"
        android:layout_width="152dp"
        android:layout_height="25dp"
        android:layout_marginLeft="30dp"
        android:background="#00000000"
        android:ems="10"
        android:inputType="phone" />
</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/skill"
        android:layout_width="125dp"
        android:layout_height="35dp"
        android:layout_marginLeft="5dp"
        android:text="Skill"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <Spinner
        android:id="@+id/spinnerskill"
        android:layout_width="152dp"
        android:layout_height="35dp"
        android:layout_marginBottom="10dp"
        android:layout_marginLeft="30dp" />
</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/textViewfactor"
        android:layout_width="125dp"
        android:layout_height="35dp"
        android:layout_marginLeft="5dp"
        android:text="Expertise"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <Spinner
        android:id="@+id/spinnerfactor"
        android:layout_width="152dp"
        android:layout_height="35dp"
        android:layout_marginLeft="30dp" />
 </LinearLayout>

</LinearLayout>

Create Custom phone Gallery app with albums

How to create a custom phone gallery with albums in android? I have made a custom phone gallery but i am not able to show the phone albums in it.please Help

I am using Luminous gallery example.i have used code in the link mentioned below: http://ift.tt/1eUbUEc

But it show images only and not the phone albums.

I Want to Make Gif(Animation) File As Live Wallpaper in android Or Make Walllaper That Change Wallpaper Auto Meticly

  • I want to create Application as Like Live Wallpaper I Want to change Wallpaper One By One In Some Particuler Time Or I Want To Use .gif file As Auto Change Wallpaper

Linear Layout with image and Text

I have to create layout that have one image and multiple textview and rating like this and i have add a line on inflating this layout with adapter

| Image| Name of Product            |
|       Desc                        |
|       Amount                      |
|       EMI details                 |
|       Rating Sybmol total Rating  |

So i have tried to create a layout like this

<RelativeLayout xmlns:android="http://ift.tt/nIICcg"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >
    <LinearLayout
        android:id="@+id/mainLinearLayout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:orientation="horizontal" >
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@mipmap/ic_launcher"
            android:layout_marginTop="5dp"
            android:layout_marginLeft="10dp"/>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:layout_marginLeft="10dp"
            android:id="@+id/text"
            android:text="Micromax Canvas Spark"
            android:textColor="@android:color/black" />
    </LinearLayout>
</RelativeLayout>

But i am confused how i can create the layout please help me in this

Android Studio 1.2.1.1 layout preview problems

After updating to Android Studio 1.2.1.1, I created a new fresh blank project and created a layout.xml

Shortly after creation, I decided to look at the preview. I went in and I saw this:

The following classes could not be instantiated: - android.support.v7.internal.widget.ActionBarOverlayLayout (Open Class, Show Exception, Clear Cache) Tip: Use View.isInEditMode() in your custom views to skip code or show sample data when shown in the IDE Exception Details java.lang.NoClassDefFoundError: Could not initialize class android.support.v7.internal.widget.ActionBarOverlayLayout   at java.lang.reflect.Constructor.newInstance(Constructor.java:408)   at android.view.LayoutInflater.inflate(LayoutInflater.java:482)   at android.view.LayoutInflater.inflate(LayoutInflater.java:414)   at com.android.layoutlib.bridge.bars.BridgeActionBar.(BridgeActionBar.java:84)   at com.android.layoutlib.bridge.bars.AppCompatActionBar.(AppCompatActionBar.java:56) Copy stack to clipboard

I have never seen it before and I had never encountered it before. Anyone have any idea how to fix this?

How to stack WebViews on top and load url into it without pushing views down

in our app, I'm loading an initial webview. Then in order to allow users to see chat history, I want to add new webviews on top on that initial one. The way I do that now is to have a linear layout wrapping the initial webview; this LinearLayout is called webview_wrapper and is in a ScrollView. Then, using a ScrollViewListener interface, when the user scrolls up past a set coordinate I create a new webview, call it newWebView, and call webview_wrapper.addView(newWebView, 0), the problem I'm having is that I want to do the loading and adding of the webview off the screen, then the user can continue to scroll up. This adding and scrolling happens inside of an onAnimationEnd method of an AnimationListener(while I make the post request for webview).

I feel like I've tried every way like calling scrollTo or scrollBy after adding the view but it's only scrolling partially. What is the best way to do this?

Horizontal ListView is not working properly

I am using TwoWayView library from Lucas to create a horizontal ListView. Everything works fine on GS3, Galaxy Note 2 Android 4.1.2 & Android 4.3.

However, I installed my app on my coworker Motorola G Android 4.44, and the ListView did not show any image. I can click on them, but I can't see any image. It only shows red or transparent color.

ListView Adpater:

public class ListViewAdapter extends BaseAdapter {
    private List<ListViewObject> ObjectList;
    private Context mContext;

    public ListViewAdapter(Context context, List<ListViewObject> newList){
    this.mContext = context;
    this.ObjectList = newList;
}

@Override
public int getCount() {
    return ObjectList.size();
}

@Override
public ListViewObject getItem(int position) {
    return ObjectList.get(position);
}

@Override
public long getItemId(int position) {
    return position;
}

@Override
public View getView(final int position, View convertView, ViewGroup parent) {       
  ViewHolder viewHolder = new ViewHolder();

  LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  if (convertView == null) {
      convertView = inflater.inflate(R.layout.listview_layout, parent, false);
      viewHolder.imageView = (ImageView)convertView.findViewById(R.id.ListViewImage); 
      viewHolder.layout = (RelativeLayout)convertView.findViewById(R.id.ListViewLayout);
      convertView.setTag(viewHolder);            
  } 
 else 
  {
     viewHolder = (ViewHolder)convertView.getTag();
  }

  Picasso.with(mContext)
  .load(getItem(position).getImageUrl())
  .resize(100, 100)  
  .centerCrop()
  .into(viewHolder.imageView);   

  return convertView;
}

class ViewHolder {
    RelativeLayout layout;
    ImageView imageView;
}

}

ListView Layout:

<RelativeLayout xmlns:android="http://ift.tt/nIICcg"
android:id="@+id/ListViewLayout"    
android:layout_width="52dp"
android:layout_height="43dp" >

<ImageView
    android:id="@+id/ListViewImage"
    android:layout_width="50dp"
    android:layout_height="40dp"
    android:scaleType="fitXY"
    android:layout_marginLeft="2px"
    android:layout_marginTop="2px" />

Main Layout:

<org.lucasr.twowayview.TwoWayView
    xmlns:android="http://ift.tt/nIICcg"
    xmlns:app="http://ift.tt/GEGVYd"
    android:id="@+id/TwoWayView"
    style="@style/TwoWayView"
    android:layout_width="match_parent"
    android:layout_height="43dp"
    android:layout_marginTop="595dp"
    android:background="@color/transparent"
    android:drawSelectorOnTop="true" />

MainActivity:

 public void ListView_Load() {
        for (File file : listFile){
            mListViewObject = new ListViewObject();
            mListViewObject.setImageUrl("file:///" + file.getAbsolutePath());
            ListViewObject_List.add(mListViewObject); 
        }        
        listViewAdapter = new ListViewAdapter(this, ListViewObject_List);
        TwoWayListView.setAdapter(listViewAdapter);
} 

I just can't figure it out why this is happening.

can someone please guide me on this?

Thank you very much for your help.

GLSurfaceView not appearing over MapView

My goal is to use OpenGL ES 2.0 with Google Maps. I would like to create an app that follows the user as they are traveling from point A to point B. I realize that this can be done using Google Maps addPolyline to draw a line, but I want to use OpenGL instead in order to show overlap of paths. I'm currently receiving an error which is due to incorrectly setting up the GLSurfaceView.

My code in the GoogleMapsTracker class is as follows:

private MapView mapView;
private GoogleMap map;
private GLSurfaceView mGLSurfaceView;

/**
 * Use this factory method to create a new instance of
 * this fragment using the provided parameters.
 */
public static GoogleMapsTracker newInstance() {
    GoogleMapsTracker fragment = new GoogleMapsTracker();
    fragment.setRetainInstance(true);
    return fragment;
}

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mapView = (MapView) getActivity().findViewById(R.id.map);
    mGLSurfaceView = new GLSurfaceView(getActivity());

    // Check if the system supports OpenGL ES 2.0
    final ActivityManager am = (ActivityManager) getActivity().getSystemService(Context.ACTIVITY_SERVICE);
    final ConfigurationInfo cInfo = am.getDeviceConfigurationInfo();
    final boolean supportsEs2 = cInfo.reqGlEsVersion >= 0x20000;

    if(supportsEs2){
        // Request an OpenGL ES 2.0 compatible context
        mGLSurfaceView.setEGLContextClientVersion(2);

        // Set the renderer to out demo renderer, defined below
        mGLSurfaceView.setRenderer(new GoogleMapsRenderer(getActivity()));
    } else {
        // This is where you could create an OpenGL ES1.x compatible
        // renderer if you wanted to support both ES 1 and ES 2
        Log.d("Does Not Support ES 2.0", "Does NOT Support ES 2.0");
    }
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v;

    if(SettingsActivity.mUnits){
        v = inflater.inflate(R.layout.google_maps_tracker_metric, container, false);
    } else {
        v = inflater.inflate(R.layout.google_maps_tracker, container, false);
    }

    // Gets the MapView from the XML layout and creates it
    mapView = (MapView) v.findViewById(R.id.map);
    mapView.onCreate(savedInstanceState);

    // Gets to GoogleMap from the MapView and does initialization stuff
    map = mapView.getMap();

    map.getUiSettings().setMyLocationButtonEnabled(true);
    map.getUiSettings().setZoomControlsEnabled(true);
    map.getUiSettings().setRotateGesturesEnabled(true);

    map.setMyLocationEnabled(true);

    map.setMapType(GoogleMap.MAP_TYPE_SATELLITE);

    // Needs to call MapsInitializer before doing any CameraUpdateFactory calls
    MapsInitializer.initialize(this.getActivity());

    // Updates the location and zoom of the MapView
    CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(new LatLng(45.669656, -111.067373), 18);
    map.animateCamera(cameraUpdate);

    mGLSurfaceView = (GLSurfaceView) v.findViewById(R.id.gl);
    mGLSurfaceView.setEGLContextClientVersion(2);
    GoogleMapsRenderer renderer = new GoogleMapsRenderer(getActivity());
    mGLSurfaceView.setEGLConfigChooser(8, 8, 8, 8, 16, 0);
    mGLSurfaceView.setRenderer(renderer);
    mGLSurfaceView.getHolder().setFormat(PixelFormat.TRANSLUCENT);
    mGLSurfaceView.setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY);

    mGLSurfaceView.setZOrderOnTop(true);

    return v;
}

My XML code:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://ift.tt/nIICcg"
xmlns:tools="http://ift.tt/LrGmb4"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >

<!--fragment
    android:name="com.google.android.gms.maps.MapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/map"
    tools:context=".MainActivity" /-->

<com.google.android.gms.maps.MapView android:id="@+id/map"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"/>

<android.opengl.GLSurfaceView
    android:id="@+id/gl"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    class="com.example.tracker.GoogleMapsRenderer"/>

</RelativeLayout>

The error I'm receiving is as follows:

    05-22 11:02:34.854  22996-22996/com.example.tracker E/AndroidRuntime﹕ FATAL     EXCEPTION: main
    Process: com.example.tracker, PID: 22996
    java.lang.NullPointerException: Attempt to invoke virtual method 'void android.opengl.GLSurfaceView$GLThread.surfaceCreated()' on a null object reference
            at android.opengl.GLSurfaceView.surfaceCreated(GLSurfaceView.java:523)
            at android.view.SurfaceView.updateWindow(SurfaceView.java:580)
            at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:176)
            at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:944)
            at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1970)
            at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1061)
            at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5885)
            at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
            at android.view.Choreographer.doCallbacks(Choreographer.java:580)
            at android.view.Choreographer.doFrame(Choreographer.java:550)
            at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
            at android.os.Handler.handleCallback(Handler.java:739)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5254)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

I'm quite certain that I'm not adding my views together properly. If anyone can point out my mistakes and a better way of implementing this idea that would be much appreciated.

How to know which drawable resource is selected

I am using Android Studio 1.2.1.1. When editing an xml layout file such as "\large-hdpi\my-layout.xml", a preview is generated in the right hand panel. In this case I have the Nexus 7 selected which is 800x1280. I expect the layout to be "large-hdpi" which it is, and I expect "hdpi" drawables to be used which it are not. The problem is, I see no way to find out exactly which drawable resource folder is being used for the preview. Sorry if it's obvious but I just don't see it.

Change text color of a predefined layout

I searched everywhere but I cannot find a solution for this simple question: I'm using a predefined layout R.layout.simple_list_item_1 but I cannot find the way to modify the text color of the TextViews inside it.

Android drawable folders fallback rule

I'm trying to understand how the drawable folders in Android works. I found that in the resource folder in our project, it has the following folders:

res/drawable-ldpi/
res/drawable-ldpi-v8/
res/drawable-ldpi-v11/
res/drawable-mdpi/
res/drawable-mdpi-v8/
res/drawable-mdpi-v11/
res/drawable-hdpi/
res/drawable-hdpi-v8/
res/drawable-hdpi-v11/
res/drawable-xhdpi/
res/drawable-xhdpi-v8/
res/drawable-xhdpi-v11/
res/drawable-xxhdpi/
res/drawable-xxhdpi-v8/
res/drawable-xxhdpi-v11/

Can someone please educate me on how the fallback mechanism on these folders works? Also what does v8 and v11 mean?

Different Layout for 4" and 5" phones

Im pretty new at developing android applications and i want to have to different layouts for 4" phone and 5" phone. Ive tried using layout-sw320dp for 4" phone(Nexus S) and layout-sw480dp for the 5" phone(Nexus 5).

However the layout gets cramped up while using the nexus S. Ive tried using layout-small and layout-normal. Didnt help.

Thanks Sahil

Design UI Android (Element between CardViews)

My question is more informative. I just want to know how to make such design. I found android application called "weather timeline" and inside of that application between CardViews (as I understand) they used this element which I pointed out in picture below. I think its just ImageView but how to set it as here. It will be interesting to know any idea about that! Thanks for attection!

enter image description here

Android Wear resource directory

I'd like an existing smartphone app to look good a smartwatch. What is the correct resource directory name for Wear layouts?

I tried res/layout-wear, but the console says that this resource directory name is invalid.

TextView and EditText cut off in LinearLayout

I have a LinearLayout with horizontal orientation in which I add some TextView and EditText dynamically. My problem is when the TextView is long, it is cut off (by height) and the EditText is invisible.

Adding padding to the views didn't solve it. When setting the LinearLayout minHeight value, the TextView is displayed correctly but the EditText is still invisible.

<LinearLayout
        android:id="@+id/content_content"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"></LinearLayout>


LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                            LinearLayout.LayoutParams.WRAP_CONTENT,
                            LinearLayout.LayoutParams.WRAP_CONTENT);

for (int i = 0; i < cntCount; i++) {
    TextView cntView = new TextView(getActivity());
    cntView.setLayoutParams(params);
    cntView.setText(cnt.get(i));

    contentContentView.addView(cntView);

    EditText answerView = new EditText(getActivity());
    answerView.setLayoutParams(params);
    answerView.setId(i);
    answerView.setHint("......");

    contentContentView.addView(answerView);

}

EDIT

I have found the solution and created a library. For those interested you can download it here

How to add new view at the top of an existing view in android

I am stuck, please help me, I have this,

<?xml version="1.0" encoding="utf-8"?>
    <android.support.v4.widget.SwipeRefreshLayout
    xmlns:android="http://ift.tt/nIICcg"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/background"
    android:id="@+id/swipeRefresh">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <LinearLayout
            android:id="@+id/contentLayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"></LinearLayout>
    </ScrollView>
</android.support.v4.widget.SwipeRefreshLayout>

Programmatically i am adding Linear Layout containing ImageView and TextView into LinearLayout of this xml file. Its okay for me. Now in Java i am doing,

refreshLayout = (SwipeRefreshLayout)view.findViewById(R.id.swipeRefresh);
refreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            refreshLayout.setRefreshing(true);

            ( new Handler()).postDelayed(new Runnable() {
                @Override
                public void run() {
                    refreshLayout.setRefreshing(false);

                }
            }, 5000);
        }
    });

Inside setOnRefreshListener I want to add new LinearLayout containing ImageView and TextView on the top of my previous view. That means all my previous LinearLayout which I added programmatically will be placed after new Layouts keeping unchanged.

I can't move from here. Any suggestion will be appreciated.

drawing sloped rectangle upper edge shape as in yahoo digest news app using xml android

am trying to draw sloped rectangle upper edge shape and use it as linear layout background as in the picture:

here is the link to the design am trying to achieve: http://ift.tt/1ApcyX7

I tried to draw a rectangular and rotate it but it didn't work fine.

so how to create that shape.

sorry about grammar mistakes, am not fluent :P.

Get an item apearing twice in the menu, but only one defined in res/menu/ xml file

I set-up a list of items for the MainActivity. Today only one item this menu.

<?xml version="1.0" encoding="utf-8"?>

<menu xmlns:android="http://ift.tt/nIICcg"
    xmlns:app="http://ift.tt/GEGVYd"
    xmlns:tools="http://ift.tt/LrGmb4"
    tools:context="fr.vincelec.sunshine.sunshine.app.ForecastFragment">

<item android:id="@+id/action_refresh"
android:title="@string/refresh"
app:showAsAction="never"/>

</menu>

Also Here is the code to enable the menu:

 @Override
public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setHasOptionsMenu(true);
}

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater){
    inflater.inflate(R.menu.forecastfragment, menu);
}

@Override
public boolean onOptionsItemSelected(MenuItem item){
    int id = item.getItemId();
    if (id == R.id.action_refresh) {
        FetchWeatherTask weatherTask = new FetchWeatherTask();
        weatherTask.execute();
        return true;
    }
    return super.onOptionsItemSelected(item);
}

But when I launch the program in my Android phone, and click on the menu, I see twice the item "Refresh", not only one item ...

I checked if there is something in MainActivity.java or main.xml but without success, It's only on my fragment file "ForecastFragment.java" (where the piece of code shown before is from) that I call the R.menu.forecastfragment .

Thanks a lot for your help :-)

layout_alignParentRight not working for relative layout inside linear layout

I have two relative layout inside linear layout. I want the first relative layout left align and the second relative layout right align. I set the following line in the second relative layout but it is not working.

android:layout_alignParentRight="true"

and my full xml file goes here.

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true"
    xmlns:android="http://ift.tt/nIICcg">

    <LinearLayout xmlns:android="http://ift.tt/nIICcg"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:weightSum="100">

    <RelativeLayout
        android:id="@+id/left"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="45"
        android:background="@drawable/listview">
        <ImageView
            android:id="@+id/leftPanelImage"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="5dp"
            android:src="@drawable/sports"/>
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="left panel"
            android:layout_marginTop="5dp"
            android:layout_below="@id/leftPanelImage"/>
    </RelativeLayout>

    <RelativeLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="45"
        android:background="@drawable/listview"
        android:layout_alignParentRight="true"
        >
        <ImageView
            android:id="@+id/rightPanelImage"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="5dp"
            android:src="@drawable/sports"/>
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="right panel"
            android:layout_marginTop="5dp"
            android:layout_below="@id/rightPanelImage"/>
    </RelativeLayout>



</LinearLayout>
</ScrollView>

My current code gives an output like this. Second layout start after first layout. I want it to start from the right from parent.

enter image description here

So my question is how can I set the second relative layout right align.

Thank you.

List View Footer is leaving spaces and not getting removed

I am using list view footer which is just a button. Whenever i am updating the list with load more button it add extra space at the bottom. Also i am trying to remove the footer when all d data is loaded.

Initialing the button in oncreate

btnLoadMore = new Button(getActivity());
        btnLoadMore.setText("Load More");
        btnLoadMore.setWidth(700);
        btnLoadMore.setHeight(30); 

Then in post Execute

                    mainAdapter = new SimpleAdapter(  
                            getActivity(), mainfooditems,
                            R.layout.list_mealiteml, new String[] {KEY_FLFOODNAME,KEY_FLCALORIES,KEY_FLFOODID,KEY_FLFAT,KEY_FLCARBS,KEY_FLPROTEIN,KEY_FLBRAND,KEY_FLSERVING}, new int[] { 
                                R.id.nameone,R.id.uiduid,R.id.mtvfoodid,R.id.fatoutputval,R.id.carbsoutval,R.id.proteinsoutval,R.id.tvbrandnameone,R.id.tvservingone });
                    // updating listview
                    listMain.addFooterView(btnLoadMore);
                    listMain.setAdapter(mainAdapter);
                    mainAdapter.notifyDataSetChanged();
state3();

And state3 is as follows:

public void state3(){
        search.clearFocus();

        setListViewHeightBasedOnChildren(listMain);
        setListViewHeightBasedOnChildren(listCustom);
        setListViewHeightBasedOnChildren(listRecent);
        tvError.setVisibility(View.INVISIBLE);
        tvMessage.setVisibility(View.INVISIBLE);
        finalfoodidint=Integer.parseInt(finalfoodid);
        if(finalfoodidint > oldlastid){

            System.out.println("1.5 + " + finalfoodidint);
            System.out.println("1.6 + " + oldlastid);

        }
        else if(finalfoodidint == oldlastid){
            //listMain.removeFooterView(btnLoadMore);
            listMain.removeFooterView(btnLoadMore);
            System.out.println("1.7 + " + finalfoodidint);
            System.out.println("1.8 + " + oldlastid);
        }
        else{
            listMain.removeFooterView(btnLoadMore);
            System.out.println("1.9 + " +finalfoodidint);
            System.out.println("1.10 + " +  oldlastid);
        }
    }

It appears

Correct way to refer multiple styles for an element [android]

I would like my element to refer / use multiple styles. Is this possible ? Or what would be the right way to do this ?

<TextView
   style="@style/bold, @style/red"
   ...
/>

How to set onTouch for a layout(XML) that is added via inflation?

I'm trying to get control buttons to pop on/off screen when the screen is tapped. They will overlay a video. The problem I'm running in to is how to create a touch event for a layout that has been inflated.
The routine is as follows:
1) set initial content to the video;
2) inflate layout(XML), that contains the controls, over the top of the video;
3)(NEED TO DO) create onTouch event for the newly inflated layout that hides/shows the buttons when the user taps the screen.

Thanks for any help!

Views in Linear Layout not getting equal space with android:layout_weight attribute

As describe in the topic's title, I have 3 TextView and I would like them to share the whole screen's width using the android:layout_weight attribute, but doing so didn't get the sought results.

LinearLayout:

<TextView
    android:id="@+id/tour1"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:background="@drawable/back"
    android:clickable="true"
    android:gravity="center"
    android:paddingBottom="8dp"
    android:paddingLeft="10dp"
    android:paddingRight="10dp"
    android:paddingTop="8dp"
    android:text="Tour \n disponibili  \n 21" />

<TextView
    android:id="@+id/tour2"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginLeft="16dp"
    android:layout_toRightOf="@+id/tour1"
    android:layout_weight="1"
    android:background="@drawable/back"
    android:clickable="true"
    android:gravity="center"
    android:paddingBottom="8dp"
    android:paddingLeft="10dp"
    android:paddingRight="10dp"
    android:paddingTop="8dp"
    android:text="Tour \n prenotabili  \n 16" />

<TextView
    android:id="@+id/tour3"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginLeft="16dp"
    android:layout_toRightOf="@+id/tour2"
    android:layout_weight="1"
    android:background="@drawable/back"
    android:clickable="true"
    android:gravity="center"
    android:paddingBottom="8dp"
    android:paddingLeft="10dp"
    android:paddingRight="10dp"
    android:paddingTop="8dp"
    android:text="Tour \n preferiti  \n 3" />

result in Portrait:

Portrait

result in Landscape:

Landscape

where is the elephant?

ps. As you can notice from the screenshot, a second problem arises: Why the first 2 TextView get stretched in height? How can I fix this unpredictable behavior?

Android Application runnig very slow on landing to a particular fragment

I am working on an android application in which there is a navigation drawer, when I click on one of the fragments it becomes extensively slow? Can anyone explain why this is happening? I have used linear layouts in that particular fragment where I am landing

Android UI Design - How to display CardView below ImageView

I am trying to display products list using CardView for my android app. I have an ImageView that is complete so I want to display other products inside the card view which will be located just below the image view. Currently I am working on my XML file for my Activity but the only way I can display the Card View is by removing the android:layout_below="@+id/custom_indicator2" on my CardView element. When I do this, the card view displays on top of my Image View. How can I do this while working on a Scroll View where in case I add more content to my Card View, I can just scroll down on my layout? The following is my code for my XML

<android.support.v4.widget.DrawerLayout
xmlns:android="http://ift.tt/nIICcg"
xmlns:tools="http://ift.tt/LrGmb4"
xmlns:custom="http://ift.tt/GEGVYd"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">

<ScrollView
    android:id="@+id/scrollView1"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="2"
    android:fillViewport="true"
    android:gravity="top" >

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context="com.example.myapp.MainActivity"
    android:background="#ffffffff">

    <com.mylibrary.slider.library.SliderMain
        android:id="@+id/slider"
        android:layout_width="match_parent"
        custom:pager_animation="Swipe"
        custom:auto_cycle="true"
        custom:indicator_visibility="visible"
        custom:pager_animation_span="1100"
        android:layout_height="160dp"/>

    <com.mylibrary.slider.library.Indicators.PagerIndicator
        android:id="@+id/custom_indicator2"
        style="@style/MyApp_AndroidImageSlider"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="20dp"
        />

    <android.support.v7.widget.CardView xmlns:custom_indicator2="http://ift.tt/GEGVYd"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        <!--When I remove the line below it shows but on top of imageview-->
        android:layout_below="@+id/custom_indicator2"
        android:id="@+id/cv"
        custom_indicator2:cardBackgroundColor="#ff39"
        >

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="16dp"
            >

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/batdroid"
                android:id="@+id/person_photo"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:layout_alignParentTop="true"
                android:layout_marginRight="16dp"
                />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/product_name"
                android:layout_toRightOf="@+id/product_photo"
                android:layout_toEndOf="@+id/product_photo"
                android:layout_alignParentTop="true"
                android:textSize="30sp"
                android:text="This is my product text!"
                />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/person_age"
                android:layout_toRightOf="@+id/product_photo"
                android:layout_toEndOf="@+id/product_photo"
                android:layout_below="@+id/product_name"
                />

        </RelativeLayout>

    </android.support.v7.widget.CardView>

</RelativeLayout>

</ScrollView>

<ListView
    android:id="@+id/navList"
    android:layout_width="290dp"
    android:layout_height="match_parent"
    android:layout_gravity="left|start"
    android:background="#ffeeeeee"/>

</android.support.v4.widget.DrawerLayout>

Update: I have tried debugging my application with an android phone that has no menu button and noticed something different. My interface shows same way as before without the cardview as below. image not showing cardview

When I try entering text onto my searchview then my cardview shows like below image showing cardview

This is how it was displaying initially on my Samsung which has a menu button. enter image description here

Please note that all I am doing on my activity is call my onCreate method which sets content to the given XML. I thought it was not necessary to give my Activity.java code because of this.

Want to access notifications from all apps inside my app.Is it possible in android?

I want to make an app where I can access all the notifications which comes to the notification center. Any help will be appreciated.

Please suggest some blog or article.I didn't find any useful info.

Thanks in advance.

Shadow for toolbar

I have the following layout for one of my screens. I have used Toolbar instead of ActionBar to get the desired look of overlying FAB. The problem is when i scroll the list, the shadow doesn't show transparency. How to deal with this?

Here is complete layout xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://ift.tt/nIICcg"
    xmlns:app="http://ift.tt/GEGVYd"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/background">

    <include
        android:id="@+id/app_bar"
        layout="@layout/app_bar" />

    <View
        android:layout_width="match_parent"
        android:layout_height="@dimen/minimum_margin"
        android:layout_below="@id/app_bar"
        android:background="@drawable/toolbar_shadow" />

    <ListView
        android:id="@+id/show_all_categories"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/app_bar"
        android:paddingTop="@dimen/minimum_margin" />

    <com.melnykov.fab.FloatingActionButton
        android:id="@+id/fabButtonforAddAccount"
        android:layout_width="@dimen/fab_dimen"
        android:layout_height="@dimen/fab_dimen"
        android:layout_alignBottom="@id/app_bar"
        android:layout_alignParentEnd="true"
        android:layout_alignParentRight="true"
        android:layout_marginBottom="@dimen/negative_half_fab_dimen"
        android:layout_marginEnd="@dimen/global_margin"
        android:layout_marginRight="@dimen/global_margin"
        android:onClick="onAddNewCategory"
        android:src="@drawable/ic_add_white_24dp"
        app:fab_colorNormal="@color/accent" />
</RelativeLayout>

XML for shadow:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://ift.tt/nIICcg"
    android:shape="rectangle">
    <gradient
        android:angle="90"
        android:endColor="@color/shadow"
        android:startColor="@android:color/transparent" />
</shape>

XML for toolbar:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://ift.tt/nIICcg"
    xmlns:app="http://ift.tt/GEGVYd"
    android:layout_width="match_parent"
    android:layout_height="@dimen/app_bar_height"
    android:background="@color/primary"
    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />

Change Spinner style programmatically

I need to implement function of changing the application theme up on button click. I have already changed successfully style of buttons, edittexts and textviews. But faced the problem of changing style for Spinner.

The only successful change is change of background color:

spinnerRoutes.setBackgroundResource(R.drawable.dark_theme_spinner_background);

BUT only background of title row changed. I need also to change textColor of rows and items, and background of spinner rows.

I have already tried alot of similar stackoverflow solutions but none of them worked.

Is it even possible to change style of spinner programatically?

How to make Android layout proportional regardless of screen size and orientation

This is my first post here. I just learned Android programming and come to this problem. I have searched a bit and found some solutions but I couldn't make my code works. So I want to know which part of my code or implementation is wrong.

So, the problem is I want to make a layout which will stays the same proportion on different screen sizes and orientation. Here are my code:

activity_main.xml

<LinearLayout
    xmlns:android="http://ift.tt/nIICcg"
    xmlns:tools="http://ift.tt/LrGmb4"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:baselineAligned="false"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="150dp" >
        <TextView
            android:layout_weight="1"
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:gravity="left"
            android:id="@+id/textView1"/>
        <TextView
            android:layout_weight="1"
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:gravity="right"
            android:id="@+id/textView2"/>
    </LinearLayout>

    <LinearLayout
        android:layout_weight="1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >
        <TextView
            android:layout_weight="1"
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:id="@+id/textView3"/>
    </LinearLayout>

    <LinearLayout
        android:layout_weight="1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >
        <TextView
            android:layout_weight="1"
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:gravity="left"
            android:id="@+id/textView4"/>

        <TextView
            android:layout_weight="1"
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:gravity="center"
            android:id="@+id/textView5"/>

        <TextView
            android:layout_weight="1"
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:gravity="right"
            android:id="@+id/textView6"/>
    </LinearLayout>

    <SeekBar
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/seekBar"
        android:max="255"/>
</LinearLayout>

I can't post screenshot at the moment, because it said "You need at least 10 reputation to post images."

So, I want to divide the screen by 3 parts vertically, and divide the top part by 2 horizontally and the bottom part by 3 horizontally and maintain their proportion regardless of screen size, resolution, and orientation.

The only part that didn't work is the top block, on the code I set it to android:layout_height="150dp" because the layout somehow is broken if I set those to android:layout_height="fill_parent". But this doesn't make the layout to be proportional if I change the orientation. Any help will be appreciated.

Thank you.

Android Layout: My images are filling only about 2/3 of my screen

I have a new Activity with related layout which works fine. Except the ImageView(s) don't cover the whole width of my screen.

I'm using Android Studio (the latest stable version) and surprisingly inside the IDE the preview of my layout looks fine. But when I run the app on my device (or emulator) it doesn't cover the whole screen.

Here is my layout design:

 <RelativeLayout xmlns:android="http://ift.tt/nIICcg"
android:id="@+id/root"
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="wrap_content">

<ScrollView
    android:id="@+id/scrollView1"
    android:layout_weight="1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">

    <LinearLayout xmlns:android="http://ift.tt/nIICcg"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <ImageView
            android:id="@+id/cat_food"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:adjustViewBounds="true"
            android:src="@drawable/cat_food" />
        <ImageView
            android:id="@+id/cat_drink"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:adjustViewBounds="true"
            android:src="@drawable/cat_drink" />
        <ImageView
            android:id="@+id/cat_coffee"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:adjustViewBounds="true"
            android:src="@drawable/cat_coffee" />
        <ImageView
            android:id="@+id/cat_shopping"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:adjustViewBounds="true"
            android:src="@drawable/cat_shopping" />
        <ImageView
            android:id="@+id/cat_offers"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:adjustViewBounds="true"
            android:src="@drawable/cat_offers" />
    </LinearLayout>
</ScrollView>
<include
    android:id="@+id/action_bar"
    layout="@layout/layout_actionbar" />

Any idea what I'm doing wrong here?

Thank you for your help.

P.S. I tried wrap_contents, match_parent, fill_parent already and none of those solved the problem.

Create custom selector

I've got 3 TextView, and I want to create a custom selector drawable which:

  • creates a rectangular border with round corners (done)
  • gets selected when the user presses one of them

The TextViews:

<LinearLayout android:id="@+id/info" android:layout_marginTop="68dp"
        android:layout_width="wrap_content" android:layout_height="fill_parent"
        android:layout_centerHorizontal="true"
        android:orientation="horizontal">
        <TextView android:id="@+id/tour1"
            android:paddingLeft="10dp" android:paddingRight="10dp"
            android:paddingTop="8dp" android:paddingBottom="8dp"
            android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:background="@drawable/back"
            android:gravity="center"
            android:text="Tour \n disponibili  \n 21"/>

        <TextView android:id="@+id/tour2" android:layout_toRightOf="@+id/tour1"
            android:paddingLeft="10dp" android:paddingRight="10dp"
            android:paddingTop="8dp" android:paddingBottom="8dp"
            android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:background="@drawable/back"
            android:gravity="center"
            android:text="Tour \n prenotabili  \n 16"
            android:layout_marginLeft="16dp"/>

        <TextView android:id="@+id/tour3" android:layout_toRightOf="@+id/tour2"
            android:paddingLeft="10dp" android:paddingRight="10dp"
            android:paddingTop="8dp" android:paddingBottom="8dp"
            android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:background="@drawable/back"
            android:gravity="center"
            android:text="Tour \n preferiti  \n 3"
            android:layout_marginLeft="16dp"/>
</LinearLayout>

My Drawable selector file, back.xml:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://ift.tt/nIICcg">
    <item>
        <shape android:shape="rectangle" >

        <stroke android:width="1dip"
            android:color="#4fa5d5"/>
        <corners android:radius="7dp"/>
    </shape>
</item>
<item  android:state_pressed="true">
    <shape android:shape="rectangle" >
        <stroke android:width="5dip"
            android:color="#ff0000"/>
        <corners android:radius="7dip" />
    </shape>
</item>

I would like to know how:

  • to successfully apply the attribute "?android:attr/selectableItemBackground"
  • or, as I just tried to do, to apply a custom one.

Unfortunately, I wasn't able to implement any of the above. In my example, the TextViews always show the first item (the one without the android:state_pressed="true" attribute) selected and when I press them they never switch to the item with the android:state_pressed="true" attribute.

Where are the flaws in my code?

Android imageView not working [duplicate]

This question already has an answer here:

My problem is android image view not showing image. its show image src path. I want to show image from android local storage[sdcard].

My xml file code is:

 ImageView imageView = (ImageView) convertView.findViewById(R.id.imgView);
 File imgFile = new File(path);
                imageView.setImageURI(Uri.fromFile(imgFile));


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://ift.tt/nIICcg"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<TextView
    android:id="@+id/lblMsgFrom"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textSize="12dp"
    android:textColor="@color/blue"
    android:textStyle="italic"
    android:padding="5dp"/>

<ImageView
    android:id="@+id/imgView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_weight="0"></ImageView>
  </LinearLayout>

Its show image path[string]. I need help.

Android EditText onClick Listener defined in Layout fails with obscure Exception

I want to define an onClick Listener for an EditText in the Layout-XML of may activity, but it always fails with an obscure Exception. This is the relevant part of my layout file:

<ImageView
     android:layout_gravity="center_horizontal|top"
     android:layout_rowSpan="3"
     android:src="@drawable/ic_action_event"
     android:onClick="onCreationClicked"
     />

<EditText
     android:id="@+id/creation_edit"
     android:focusable="false"
     android:clickable="true"
     android:layout_gravity="fill_horizontal"
     android:hint="@string/enter_creation"
     android:onClick="onCreationClicked"
     style="@style/PickerEditText"
     />

When I click on the ImageView the associated method is executed and a DialogFragment is started. When I click on the EditText I get the following Exception:

    java.lang.IllegalStateException: Could not find a method onCreationClicked(View) in the activity class android.support.v7.internal.widget.TintContextWrapper for onClick handler on view class android.support.v7.widget.AppCompatEditText with id 'creation_edit'
            at android.view.View$1.onClick(View.java:3994)
            at android.view.View.performClick(View.java:4756)
            at android.view.View$PerformClick.run(View.java:19749)
            at android.os.Handler.handleCallback(Handler.java:739)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5221)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
     Caused by: java.lang.NoSuchMethodException: onCreationClicked [class android.view.View]
            at java.lang.Class.getMethod(Class.java:664)
            at java.lang.Class.getMethod(Class.java:643)
            at android.view.View$1.onClick(View.java:3987)
            at android.view.View.performClick(View.java:4756)
            at android.view.View$PerformClick.run(View.java:19749)
            at android.os.Handler.handleCallback(Handler.java:739)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5221)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

I am currently testing on a Samsung S4 (Android 5.0.1) API 21 and AppCompat Library in Version v7 22.1.0

Any ideas?

Implementing android animation like gmail inbox

I'm writing an android app using romannurik`s Android-SwipeToDismiss using google cardview items. Swiping the cards is enabled in the app using the above romannuriks library.

Currently my problem is in implementing, another view come in background while i'm swiping the card, just like the implementation in gmail where I can see archive and undo while I'm swiping the card.

Any ideas would be greatly helpful.

Highlighting a focused edit text

I have been looking on how to highlight a focused edit text form field in an Android app.

When I focus my email field, there is no visual feedback.

What sort of visual feedback should I provide ? Is there a standard on what the user expects ?

I was thinking of some background color highlight or some field border color.

Any way to achieve this ?

My layout is:

<EditText
    android:id="@+id/login_email_edittext"
    style="@style/editext_graybg"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:drawableLeft="@drawable/ic_username"
    android:drawableStart="@drawable/ic_username"
    android:hint="@string/login_email_hint" >

    <requestFocus />
</EditText>

And the style:

<style name="editext_graybg" parent="android:Widget.EditText">
    <item name="android:background">@drawable/editext_bg_gray</item>
    <item name="android:drawablePadding">@dimen/pad_10dp</item>
    <item name="android:ems">10</item>
    <item name="android:inputType">textEmailAddress</item>
    <item name="android:paddingLeft">@dimen/pad_10dp</item>
    <item name="android:paddingRight">@dimen/pad_10dp</item>
    <item name="android:textColor">@color/black</item>
    <item name="android:textSize">@dimen/txt_18sp</item>
</style>

How to implements progress indicator like Quizup on Android

I want to design progress indicator which will be changed dynamically(increase) after each user input.

  • I tried to use View with background color and change height param dynamically, But i am asking if there is a library that may give me beautiful color effects.

Removing RelativeLayout.END_OF which is added programmatically

I'm trying to remove RelativeLayout.END_OF from a view's layout parameters which is added programmatically, but it seems that just writing viewLayoutParams.removeRule(RelativeLayout.END_OF) doesn't work and I don't know why!

I'm trying to make a live preview based on options and here they are my codes.

XML:

<RelativeLayout
    android:id="@+id/liveExample"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/liveExampleLabel">

    <TextView
        android:id="@+id/iranianDate"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Monday, 8 Bahman 1370"
        android:textAppearance="@style/AppTheme.Text.IranianDate"
        tools:ignore="HardcodedText"/>

    <TextView
        android:id="@+id/islamicDate_label"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_below="@id/iranianDate"
        android:text="@string/islamic"
        android:textAppearance="@style/AppTheme.Text.IslamicLabel"/>

    <TextView
        android:id="@+id/islamicDate"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="8 Rajab 1436"
        android:layout_below="@id/iranianDate"
        android:textAppearance="@style/AppTheme.Text.IslamicDate"
        tools:ignore="HardcodedText"/>
</RelativeLayout>

Java:

private void updateLivePreviewDatesLayout(boolean isChecked) {
RelativeLayout.LayoutParams iranianDateLayoutParams = (RelativeLayout.LayoutParams) iranianDate
        .getLayoutParams();
RelativeLayout.LayoutParams islamicDateLayoutParams = (RelativeLayout.LayoutParams) islamicDate
        .getLayoutParams();
if (isChecked) {
    iranianDateLayoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
    islamicDateLayoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
    islamicDateLayoutParams.setMarginStart(0);
    islamicDateLayoutParams.removeRule(RelativeLayout.END_OF);
} else {
    iranianDateLayoutParams.removeRule(RelativeLayout.CENTER_HORIZONTAL);
    islamicDateLayoutParams.removeRule(RelativeLayout.CENTER_HORIZONTAL);
    if (displayIslamicLabel.isChecked()) {
        islamicDateLayoutParams.setMarginStart(8);
        islamicDateLayoutParams.addRule(RelativeLayout.END_OF,
                R.id.islamicDate_label);
    }
}
iranianDate.setLayoutParams(iranianDateLayoutParams);
islamicDate.setLayoutParams(islamicDateLayoutParams);
}

centerHorizontal.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        editor.putBoolean("w_centerHorizontal", isChecked).apply();
        updateLivePreviewDatesLayout(isChecked);
    }
});

It works for the first time (removing toEndOf layout parameter) but for the next time, it won't be removed because I added the parameter programmatically.

UPDATE

I need to add the layout_toEndOf layout parameter to the view because the default position of the view is related to another view which they should be next together and after that, the view may be positioned at the center of its layout so I should remove the RelativeLayout.END_OF and instead add RelativeLayout.CENTER_HORIZONTAL parameter. It's good to know that these two parameters won't work together and RelativeLayout.END_OF is more powerful that the other parameter.

Screenshots

Before checking the option: The default position of the "4 Sha'ban 1436" is end of the "Islamic" label.

Before checking the option

After checking the option: the "4 Sha'ban 1436" not positioned at center because the RelativeLayout.END_OF parameter is not removed correctly and that's the problem!

After checking the option

How do I start layout with many linearlayout inside it with new row position?

I just started using this plugin : http://ift.tt/1dwQi3y

I have implement it inside my layout with multiple LinearLayout and the dragging is working. But now I have a new problem which is, how do I start the app with the row position after dragging?

mardi 26 mai 2015

Setting a background view animation for google card view

I'm writing an android app which uses romannurik`s Android-SwipeToDismiss. I'm using google cardview for my view items. Swiping the cards is enabled in the app using the above romannuriks library.

Now i'm facing difficulty in figuring out regarding how to make another view come in background while i'm swiping the card, just like the implementation in gmail. When I swipe gmail card, I get background view containing archive and undo.

Any ideas regarding how to implement this would be really helpful.

Abnormal Behavior with RadioButton

I am using RadioButton in my layout. Where i have provided background to the RadioButton. Below is the code

<RadioGroup
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="horizontal">

    <RadioButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:button="@null"
        android:background="@drawable/rb_spain"
        android:id="@+id/am_rb_spain" />

    <RadioButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:button="@null"
        android:background="@drawable/rb_germany"
        android:layout_marginLeft="@dimen/margin_15"
        android:layout_marginRight="@dimen/margin_15"
        android:id="@+id/am_rb_german" />

    <RadioButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:button="@null"
        android:background="@drawable/rb_english"
        android:id="@+id/am_rb_english" />

</RadioGroup>

RadioButton background drawable

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://ift.tt/nIICcg" >
    <item android:state_checked="false" android:drawable="@drawable/ic_spain" />
    <item android:state_checked="true" android:drawable="@drawable/ic_spain_pressed" /> //pressed image is Large in size
    <item android:drawable="@drawable/ic_spain" /> <!-- default -->
</selector>

I have saved the selection in TinyDB so that app will remember my selection whenever i open my app. But whenever i open my app the default selected RadioButton background Appears Large. I have taken all the images of same size in drawable's with same padding.

First flag is Default selected here. But it appear to be slightly large in size

First flag is Default selected here

Now i have pressed 2nd flag. But first flag is not coming to its normal state.

Now i have selected 2nd flag

i want to change backgroud color of pay sdk

I want to change background color of sdk paypal integration how to do that . where to find That layout of paypal.I am want to integrate in android application,but i have change only backgoud of paypal sdk.

Relative Layout does not scroll after adding scrollview

Good day. I have a layout code shown below

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
    xmlns:android="http://ift.tt/nIICcg"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:fillViewport="true" >

    <RelativeLayout xmlns:android="http://ift.tt/nIICcg"
        xmlns:tools="http://ift.tt/LrGmb4"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        tools:context=".MainActivity">

        <include
            android:id="@+id/toolbar"
            layout="@layout/app_bar" />


        <android.support.v4.view.ViewPager
            android:id="@+id/viewpager"
            android:layout_width="match_parent"
            android:layout_height="165dp"
            android:layout_below="@+id/toolbar" />

        <RelativeLayout
            android:id="@+id/relativeLayout"
            android:layout_width="match_parent"
            android:layout_height="25dp"
            android:layout_alignBottom="@id/viewpager"
            android:background="#33000000">

            <TextView
                android:id="@+id/tv_image_description"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:layout_centerVertical="true"
                android:paddingLeft="10dp"
                android:text="Shop Name"
                android:textColor="#FFF" />


            <LinearLayout
                android:id="@+id/ll_point_group"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentEnd="true"
                android:layout_alignParentRight="true"
                android:layout_centerVertical="true"
                android:orientation="horizontal"
                android:paddingRight="10dp">

            </LinearLayout>
        </RelativeLayout>


        <android.support.v7.widget.RecyclerView
            android:id="@+id/cardList"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@+id/relativeLayout" />


    </RelativeLayout>
</ScrollView>

I have connected my recyclerview with a list of data but why is RecyclerView Layout is scrollable but not the entire Relativelayout. I have wrapped the RelativeLayout with ScrollView. it seems like not working. please see the image below This is how to layout look like

Do let me know if you guys have better solution for this. Billion thanks.

How to show data inside the PopupWindow in android?

There are 10 buttons on absolute layout and i Want that onClick a popwindow will show and inside the window I want 4 ImageViews and 4 ImageButtons (ImageButtons will used for playing an audio.) kindly help me out. the popup window's orientation will be landscape and align to the right side.

Android Nexus5 Navigation Hiding Layout

I'm using Nexus5 for testing application and I got issue that is Navigation bar hides Bottom Layout

Nexus5 Navigation Bar

Main container is RelativeLayout which has LinearLayout on the bottom. other devices are fine and showing well but only Nexus5 has that issue because I think it has navigation bar on the bottom of screen.

Anyone has the same issue that you got? If you do, please share it.

How can I correctly resize the layout when the keyboard appears?

In Android I have reproduced the following layout :

enter image description here

In this way :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://ift.tt/nIICcg"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#94F734"
    android:orientation="vertical">

<LinearLayout  
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="48dp"
    android:layout_marginLeft="48dp"
    android:padding="0dp">
    <include 
        layout="@layout/header"/>
</LinearLayout>

  <RelativeLayout 
    android:id="@+id/body"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginLeft="48dp"
    android:layout_marginRight="48dp"
    android:layout_marginBottom="48dp"
    android:paddingTop="96dp"
    android:background="#463779B3"
    android:visibility="visible"
   >

       <TextView
        android:id="@+id/name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

        android:textSize="28dp"
        android:text="title"
        android:layout_above="@+id/code"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="48dp"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:textColor="#000000"
     />

    <EditText
        android:id="@+id/code"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:hint="Insert here "
        android:background="@drawable/back_item_edit"
        android:textColor="#FFFFFF"
        android:layout_centerVertical="true"
        android:layout_marginLeft="36dp"
        android:layout_marginRight="36dp">
     <requestFocus />

    </EditText>

    <Button
        android:id="@+id/prova"
        android:layout_below="@id/code"
        style="@style/initialButton"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="26dp"
        android:text="Connect"
        android:textColor="#000000"
        android:layout_alignLeft="@id/code"
        android:layout_alignRight="@id/code"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:visibility="visible"
         />



    </RelativeLayout>






</LinearLayout>

But when I click on "insert here" one problem appears : the layout is not correctly resized and doesn't fit in the little screen.

I thought to use a scrollview, but I don't know how to use it.

WHen the keyboard appears I would to show :

  • header (if there is room)
  • title (if there is room)
  • insert here
  • connect
  • green part of layout (if there is room)
  • keyboard

Is there a way to resolve my problem ?

which layout is best for moving buttons within

OK first I'm not actually moving buttons I'm moving imageviews that have an onclick listener. What I want to do is drag multiple imageviews around inside a layout. I was going to use a FrameLayout but it seems that wont work for multiple items.
Can anyone tell me which layout is suitable for this?

thanks in advance

android theme using multiple colors.xml

I am new to android development, so please bear with me. My app elements (button color, background color, text color, divider color etc.) uses colors from the colors.xml using "@color/mycolor" for example.

My colors.xml looks like:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="mycolor">#202020</color>
    <color name="white">#FFFFFF</color>
    <color name="whitehint">#50FFFFFF</color>
    <color name="primary">#673AB7</color>
    <color name="primary_dark">#512DA8</color>
    <color name="primary_light">#D1C4E9</color>
    <color name="accent">#794cc9</color>
    <color name="primary_text">#212121</color>
    <color name="secondary_text">#a4a4a4</color>
    <color name="icons">#FFFFFF</color>
    <color name="divider">#B6B6B6</color>
</resources>

Now I have a menu where the user can select a different theme which I want to use a second colors2.xml for example which will have the same color names but a different hex code for the keys. How do I go about which xml file does my app references?

How can I divide a screen in 2 equal parts : one with an image and the other with textviews?

I'm making an Android news app and when I or the user would access a list of news, each news would take the whole screen and would be divided in two parts (50/50) : first part would be the image and the other half would be the textviews (for the title, date and article). A couple of apps are using the same trick.

I've tried many options but I cannot manage to make them fit into my screen and get what I'm looking for.

As you will see I've added the layout_weight parameter but it does not make any difference at all.

Any idea anyone ??

Here's my xml file :

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://ift.tt/nIICcg"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:weightSum="1" >

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:src="@drawable/news_hockey2"
        android:adjustViewBounds="true" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="title"
        android:id="@+id/title"
        android:layout_marginTop="5dp" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="date_of_pub"
        android:id="@+id/date_of_pub"
        android:layout_marginTop="5dp"
        android:layout_weight="0.1" />


    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:text="link"
        android:id="@+id/link"
        android:layout_marginBottom="25dp"
        android:layout_marginTop="5dp" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="article"
        android:id="@+id/article"
        android:layout_marginTop="10dp"
        android:layout_marginBottom="15dp" />

</LinearLayout>

How to get Audio source for FM audio stream recording?

I am trying to record FM radio audio stream. I am able to record with one audio source which is 9 for Motorola.

But when i tried with different phones it not working. So i wondering how to get this audio source dynamically.

This is how i am recording

 //RX_SRC is the FM receiving Antenna
   mRecorder = new AudioRecord(10, sampleRateInHz,
                            channelConfigIn,
                            AudioFormat.ENCODING_PCM_16BIT,
                            bufferSizeInBytes);                 

Please help me.

Android Studio Layout Preview Source

I'm looking to view the source code for the Layout Preview (generated from XML) in Android Studio. Does anyone know which files the relevant code is in within the SDK, or is it somewhere else entirely? I only ask because there are so many source files for Android Studio and the Android SDK, it would take a long time to search through all of them for this code.

How to set textView as right as possible and set textView show only a part of text?

I have the xml code shown below. Everything is working as it should except the final textView( id locationTextView) which won't stay right. I want it to stay as right as possible, but I can't do that(it still appears straight after the linear Layout).Should I set a left margin?. And for the textView1 how can I make it to show only a certain part of the whole text, because I have texts of different lengths and they ruin the layout.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://ift.tt/nIICcg"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@color/product_list_item_bg"
    android:descendantFocusability="blocksDescendants">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal">

        <ImageView
            android:id="@+id/icon"
            android:layout_width="72dip"
            android:layout_height="72dip"
            android:layout_margin="3dip"
            android:adjustViewBounds="true"
            android:contentDescription="@string/descr_image"
            android:scaleType="centerCrop" />

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <TextView
                android:id="@+id/item"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:layout_marginTop="5dp"
                android:padding="2dp"
                android:text="Medium Text"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:textColor="#33CC33" />

            <TextView
                android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:text="TextView" />

        </LinearLayout>
        <TextView
            android:gravity="right"
            android:layout_width="72dip"
            android:layout_height="72dip"
            android:layout_marginTop="0dp"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:id="@+id/locationTextView"
            android:layout_gravity="right" />
    </LinearLayout>
</RelativeLayout>

How to show a ViewGroup on click without changing the screen in Android

I have two buttons on home screen A & B. On clicking either of them, respective forms should appear in the same screen. I am not able to show the forms without launching a new screen.

Custom TextView features using android:background tag more than once

I have a problem with the android:background tag, which I am only able to use once, while I need more than once feature for my TextViews. More details below:

I have 3 TextView:

<LinearLayout android:id="@+id/info" android:layout_marginTop="68dp"
        android:layout_width="wrap_content" android:layout_height="fill_parent"
        android:layout_centerHorizontal="true"
        android:orientation="horizontal">

        <TextView android:id="@+id/tour1"
            android:paddingLeft="10dp" android:paddingRight="10dp"
            android:paddingTop="8dp" android:paddingBottom="8dp"
            android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:background="@drawable/back"
            android:gravity="center"
            android:text="Tour \n disponibili  \n 21"/>

        <TextView android:id="@+id/tour2" android:layout_toRightOf="@+id/tour1"
            android:paddingLeft="10dp" android:paddingRight="10dp"
            android:paddingTop="8dp" android:paddingBottom="8dp"
            android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:background="@drawable/back"
            android:gravity="center"
            android:text="Tour \n prenotabili  \n 16"
            android:layout_marginLeft="16dp"/>

        <TextView android:id="@+id/tour3" android:layout_toRightOf="@+id/tour2"
            android:paddingLeft="10dp" android:paddingRight="10dp"
            android:paddingTop="8dp" android:paddingBottom="8dp"
            android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:background="@drawable/back"
            android:gravity="center"
            android:text="Tour \n preferiti  \n 3"
            android:layout_marginLeft="16dp"/>
    </LinearLayout>

shown here:

enter image description here

The TextView border is obtained with this file, back.xml, included in res/drawable folder:

<shape xmlns:android="http://ift.tt/nIICcg"   
    android:shape="rectangle" >
    <!--<solid android:color="#ffffff" />-->
    <stroke android:width="1dip" android:color="#4fa5d5"/>
</shape>

Since I am already using the background tag to input the back.xml file and create a rectangular border for the TextViews, I don't know how to use it for my other needs, which are:

  • get a border for the TextView WITH also round corners
  • get an icon as background of the TextView as shown here: here

As far as I know I can only do this with the tag background, which is already used to get the back.xml drawable.

How can I fulfill my needs?

Connect gallery to Camera

I'm doing an Android App in which I take a photo with camera, then there is A Gallery (of the photos), under an ImageView (the photo in format of Bitmap), and textviews in which I say name of photo (date), and position (latitude and longitude, with GPS). Obviously, if I click in an Image of the gallery, it'll appear in full screen! My problems are: 1. How to connect gallery with ImageViews (bitmap) by Camera. 2. How do I "save" the gallery? (Maybe with Hashmap, but I don't know what's that!)...Please don't make complicated codes cause this isn't an advanced android exam! Sorry for my terrible english!! This is my code:`

package com.example.app1;

import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.location.Address;
import android.location.Geocoder;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.widget.ImageView;
import android.widget.TextView;

public class MainActivity extends Activity {
static final int REQUEST_IMAGE_CAPTURE = 1;
ImageView mImageView;




@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main); 
    mImageView=(ImageView) findViewById(R.id.foto);
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
        startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
    }
    }
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data){              
    if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
        Bundle extras = data.getExtras();
        Bitmap imageBitmap = (Bitmap) extras.get("data");
        mImageView.setImageBitmap(imageBitmap);
    }
}
String mCurrentPhotoPath;
private File createImageFile() throws IOException {
    // Create an image file name
    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new    Date());
    String imageFileName = "JPEG_" + timeStamp + "_";
    File storageDir = Environment.getExternalStoragePublicDirectory(
            Environment.DIRECTORY_PICTURES);
    File image = File.createTempFile(
        imageFileName,  /* prefix */
        ".jpg",         /* suffix */
        storageDir      /* directory */
    );
    // Save a file: path for use with ACTION_VIEW intents
    mCurrentPhotoPath = "file:" + image.getAbsolutePath();
    return image;
}
static final int REQUEST_TAKE_PHOTO = 1;
private void dispatchTakePictureIntent() {
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    // Ensure that there's a camera activity to handle the intent
    if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
        // Create the File where the photo should go
        File photoFile = null;
        try {
            photoFile = createImageFile();
        } catch (IOException ex) {
            // Error occurred while creating the File
        }
        // Continue only if the File was successfully created
        if (photoFile != null) {
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
                    Uri.fromFile(photoFile));
            startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);
        }
    }
}
private void galleryAddPic() {
    Intent mediaScanIntent = new    Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
    File f = new File(mCurrentPhotoPath);
    Uri contentUri = Uri.fromFile(f);
    mediaScanIntent.setData(contentUri);
    this.sendBroadcast(mediaScanIntent);
}
private void setPic() {
    // Get the dimensions of the View
    int targetW = mImageView.getWidth();
    int targetH = mImageView.getHeight();
    // Get the dimensions of the bitmap
    BitmapFactory.Options bmOptions = new BitmapFactory.Options();
    bmOptions.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions);
    int photoW = bmOptions.outWidth;
    int photoH = bmOptions.outHeight;
    // Determine how much to scale down the image
    int scaleFactor = Math.min(photoW/targetW, photoH/targetH);
    // Decode the image file into a Bitmap sized to fill the View
    bmOptions.inJustDecodeBounds = false;
    bmOptions.inSampleSize = scaleFactor;
    bmOptions.inPurgeable = true;
    Bitmap bitmap = BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions);
    mImageView.setImageBitmap(bitmap);
}
//GPS
private String providerId = LocationManager.GPS_PROVIDER;
private Geocoder geo = null;
private LocationManager locationManager=null;
private static final int MIN_DIST=20;
private static final int MIN_PERIOD=30000;
/*onLocationChanged è il cuore del listener e viene 
invocato ogni volta che nuove informazioni di posizione sono state   recapitate.*/
private LocationListener locationListener = new LocationListener() 
{
    @Override
    public void onLocationChanged(Location location) {
        // TODO Auto-generated method stub
        updateGUI(location);
    }
    @Override
    public void onProviderDisabled(String provider) {
        // TODO Auto-generated method stub
    }
    @Override
    public void onProviderEnabled(String provider) {
        // TODO Auto-generated method stub
        }
    @Override
    public void onStatusChanged(String provider, int status, Bundle extras)    {            // TODO Auto-generated method stub}
};
/*L’oggetto Location contiene tutto ciò che è stato appreso dall’ultima        misurazione del posizionamento e 
viene inviata al metodo updateGUI per riflettere gli aggiornamenti sulla     interfaccia utente: */ 
private void updateGUI(Location location) 
{
    Date timestamp = new Date(location.getTime());     //ecco dove si trova la
    updateText(R.id.timestamp, timestamp.toString());  //data (nome della foto!!)
    double latitude = location.getLatitude();
    updateText(R.id.latitude, String.valueOf(latitude));
    double longitude = location.getLongitude();
    updateText(R.id.longitude, String.valueOf(longitude));
    new AddressSolver().execute(location);
}
private void updateText(int id, String text) 
{
    TextView textView = (TextView) findViewById(id);
    textView.setText(text);
}
private class AddressSolver extends AsyncTask<Location, Void, String>
{
@Override
protected String doInBackground(Location... params) 
{
    Location pos=params[0];
    double latitude = pos.getLatitude();
    double longitude = pos.getLongitude();

    List<Address> addresses = null;
    try
    {
        addresses = geo.getFromLocation(latitude, longitude, 1);
    } 
    catch (IOException e) 
    {               
    }
    if (addresses!=null)
    {
        if (addresses.isEmpty())   { 
            return null;
          }
          else {
             if (addresses.size() > 0) 
             {   
                 StringBuffer address=new StringBuffer();
                 Address tmp=addresses.get(0);
                 for (int y=0;y<tmp.getMaxAddressLineIndex();y++)
                    address.append(tmp.getAddressLine(y)+"\n");
                 return address.toString();
             }
          }
    }
    return null;
}

}

@Override
protected void onResume() 
{
    super.onResume();
    geo=new Geocoder(this, Locale.getDefault());
    locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
    Location location =  locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
    if (location!=null)
        updateGUI(location);
    locationManager.requestLocationUpdates(providerId, MIN_PERIOD,MIN_DIST, locationListener);
}

   @Override
   protected void onPause() 
    {
      super.onPause();
      if (locationManager!=null &&  locationManager.isProviderEnabled(providerId))
        locationManager.removeUpdates(locationListener);
}
}

And this is my layout (activity_main.xml):

<LinearLayout xmlns:android="http://ift.tt/nIICcg"
  xmlns:tools="http://ift.tt/LrGmb4"
  android:orientation="vertical"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:paddingBottom="@dimen/activity_vertical_margin"
   android:paddingLeft="@dimen/activity_horizontal_margin"
   android:paddingRight="@dimen/activity_horizontal_margin"
   android:paddingTop="@dimen/activity_vertical_margin"
   tools:context="com.example.app1.MainActivity" >

   <Gallery android:id="@+id/gallery1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="16dp"/>

 <ImageView
    android:id="@+id/foto"
    android:layout_width="fill_parent"
    android:layout_height="450sp" />

 <TableLayout 
  android:layout_width="wrap_content"
  android:layout_height="wrap_content">
  <TableRow android:padding="5dp">
    <TextView android:text="Nome foto:" android:padding="5dp"
    android:layout_width="wrap_content" android:layout_height="wrap_content"/>
    <TextView android:id="@+id/timestamp" android:padding="5dp"
    android:layout_width="wrap_content" android:layout_height="wrap_content"/>
</TableRow>
<TableRow android:padding="5dp">
    <TextView android:text="Latitudine:" android:padding="5dp"
    android:layout_width="wrap_content" android:layout_height="wrap_content"/>
    <TextView android:id="@+id/latitude" android:padding="5dp"
    android:layout_width="wrap_content" android:layout_height="wrap_content"/>
</TableRow>
<TableRow android:padding="5dp">
    <TextView android:text="Longitudine:" android:padding="5dp"
    android:layout_width="wrap_content" android:layout_height="wrap_content"/>
    <TextView android:id="@+id/longitude" android:padding="5dp"
    android:layout_width="wrap_content"        android:layout_height="wrap_content"/>
</TableRow>
</TableLayout>
</LinearLayout>