Widget click not responding - java

I'm trying to set to all of the views that are in the widget a click listener that should open an activity upon a click, but for now seems that its not working. Can someone tell me what am I doing wrong?
Here is my code:
public class AthanWidget extends AppWidgetProvider {
private SharedPreferences prefs;
private boolean PAID = false;
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
final int N = appWidgetIds.length;
prefs = context.getSharedPreferences(context.getPackageName(),
Context.MODE_PRIVATE);
SimpleDateFormat sdf = new SimpleDateFormat("EEE, MMM d, yyyy");
String currentDateandTime = sdf.format(new Date());
PAID = prefs.getBoolean(Constants.ITEM_PURCHASED, false);
// TODO CHECK IF IMAGE IS FROM SD OR A RESOURCE IS
// Perform this loop procedure for each App Widget that belongs to this
// provider
for (int i = 0; i < N; i++) {
int appWidgetId = appWidgetIds[i];
// Create an Intent to launch ExampleActivity
Intent intent;
if (!PAID) {
intent = new Intent(context, RemoveAds.class);
} else {
intent = new Intent(context, Main.class);
}
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
intent, 0);
// Get the layout for the App Widget and attach an on-click listener
// to the button
RemoteViews views = new RemoteViews(context.getPackageName(),
R.layout.widget_layout);
views.setOnClickPendingIntent(appWidgetId, pendingIntent);
views.setTextViewText(R.id.widget_date_title, currentDateandTime);
views.setTextViewText(R.id.widget_arabic_date_title, arabianDate());
displayPrayerTimes(views);
if (prefs.getInt(Constants.BG_ID_PREFS, 1) < 0) {
Bitmap myBitmap = BitmapFactory.decodeFile(prefs.getString(
Constants.BG_SD_PATH, ""));
views.setImageViewBitmap(R.id.widget_bg, myBitmap);
} else {
views.setImageViewResource(R.id.widget_bg,
prefs.getInt(Constants.BG_ID_PREFS, R.drawable.bg24));
}
// Tell the AppWidgetManager to perform an update on the current app
// widget
appWidgetManager.updateAppWidget(appWidgetId, views);
}
}
private void displayPrayerTimes(RemoteViews views) {
if (PAID) {
views.setTextViewText(
R.id.widget_fajr,
prefs.getString(Constants.FARJ_ID + "w", "DISABLED").split(
",")[0]);
views.setTextViewText(R.id.widget_dhurh,
prefs.getString(Constants.DHUHR_ID + "w", "DISABLED")
.split(",")[0]);
views.setTextViewText(
R.id.widget_isha,
prefs.getString(Constants.ISHA_ID + "w", "DISABLED").split(
",")[0]);
views.setTextViewText(
R.id.widget_asr,
prefs.getString(Constants.ASR_ID + "w", "DISABLED").split(
",")[0]);
}
views.setTextViewText(
R.id.widget_shorrok,
prefs.getString(Constants.SHORROK_ID + "w", "DISABLED").split(
",")[0]);
views.setTextViewText(
R.id.widget_maghrib,
prefs.getString(Constants.MAGHRIB_ID + "w", "DISABLED").split(
",")[0]);
}
private String arabianDate() {
Date date = new Date(); // هنا التاريخ الصليبي
Calendar cl = Calendar.getInstance();
cl.setTime(date);
final String[] iMonthNames = { "Muharram", "Safar", "Rabi'ul Awwal",
"Rabi'ul Akhir", "Jumadal Ula", "Jumadal Akhira", "Rajab",
"Sha'ban", "Ramadan", "Shawwal", "Dhul Qa'ada", "Dhul Hijja" };
Chronology iso = ISOChronology.getInstanceUTC();
Chronology hijri = IslamicChronology.getInstanceUTC();
LocalDate todayIso = new LocalDate(cl.get(Calendar.YEAR),
cl.get(Calendar.MONTH) + 1, cl.get(Calendar.DAY_OF_MONTH), iso);
LocalDate todayHijri = new LocalDate(todayIso.toDateTimeAtStartOfDay(),
hijri);
return todayHijri.getDayOfMonth() + " "
+ iMonthNames[todayHijri.getMonthOfYear()] + " "
+ todayHijri.getYear();
}
}
and my widget layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="#+id/widget_bg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha=".85"
android:contentDescription="#string/app_name"
android:scaleType="centerCrop" />
<TextView
android:id="#+id/widget_toptext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:paddingTop="10dp"
android:text="#string/widget_title"
android:textColor="#android:color/white"
android:textSize="15sp" />
<TextView
android:id="#+id/widget_date_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/widget_toptext"
android:layout_centerHorizontal="true"
android:textColor="#android:color/white"
android:textSize="15sp" />
<TextView
android:id="#+id/widget_arabic_date_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/widget_date_title"
android:layout_centerHorizontal="true"
android:textColor="#android:color/white"
android:textSize="15sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#80000000"
android:baselineAligned="false"
android:orientation="horizontal"
android:paddingBottom="10dp"
android:paddingTop="10dp" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableEnd="#drawable/w_pray_sun_up"
android:drawableRight="#drawable/w_pray_sun_up"
android:gravity="bottom"
android:paddingRight="2dp"
android:text="#string/ar_fajr"
android:textColor="#android:color/white"
android:textSize="12sp" />
<TextView
android:id="#+id/widget_fajr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/voir"
android:textColor="#android:color/white"
android:textSize="12sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/fajr"
android:textColor="#android:color/white"
android:textSize="12sp" />
</LinearLayout>
<TextView
android:layout_width="1dp"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:background="#android:color/white" />
<!-- delete this -->
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableEnd="#drawable/w_pray_sun_up"
android:drawableRight="#drawable/w_pray_sun_up"
android:gravity="bottom"
android:paddingRight="2dp"
android:text="#string/ar_shorok"
android:textColor="#android:color/white"
android:textSize="12sp" />
<TextView
android:id="#+id/widget_shorrok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/voir"
android:textColor="#android:color/white"
android:textSize="12sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/shorrok"
android:textColor="#android:color/white"
android:textSize="12sp" />
</LinearLayout>
<TextView
android:layout_width="1dp"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:background="#android:color/white" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableEnd="#drawable/w_pray_dhurh"
android:drawableRight="#drawable/w_pray_dhurh"
android:gravity="bottom"
android:paddingRight="2dp"
android:text="#string/ar_dhuhr"
android:textColor="#android:color/white"
android:textSize="12sp" />
<TextView
android:id="#+id/widget_dhurh"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/voir"
android:textColor="#android:color/white"
android:textSize="12sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/dhuhr"
android:textColor="#android:color/white"
android:textSize="12sp" />
</LinearLayout>
<TextView
android:layout_width="1dp"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:background="#android:color/white" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableEnd="#drawable/w_pray_asr"
android:drawableRight="#drawable/w_pray_asr"
android:gravity="bottom"
android:paddingRight="2dp"
android:text="#string/ar_asr"
android:textColor="#android:color/white"
android:textSize="12sp" />
<TextView
android:id="#+id/widget_asr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/voir"
android:textColor="#android:color/white"
android:textSize="12sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/asr"
android:textColor="#android:color/white"
android:textSize="12sp" />
</LinearLayout>
<TextView
android:layout_width="1dp"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:background="#android:color/white" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableEnd="#drawable/w_pray_maghreb"
android:drawableRight="#drawable/w_pray_maghreb"
android:gravity="bottom"
android:paddingRight="2dp"
android:text="#string/ar_magrib"
android:textColor="#android:color/white"
android:textSize="12sp" />
<TextView
android:id="#+id/widget_maghrib"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/voir"
android:textColor="#android:color/white"
android:textSize="12sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/maghrib"
android:textColor="#android:color/white"
android:textSize="12sp" />
</LinearLayout>
<TextView
android:layout_width="1dp"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:background="#android:color/white" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableEnd="#drawable/w_pray_moon"
android:drawableRight="#drawable/w_pray_moon"
android:gravity="bottom"
android:paddingRight="2dp"
android:text="#string/ar_isha"
android:textColor="#android:color/white"
android:textSize="12sp" />
<TextView
android:id="#+id/widget_isha"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/voir"
android:textColor="#android:color/white"
android:textSize="12sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/isha_a"
android:textColor="#android:color/white"
android:textSize="12sp" />
</LinearLayout>
<!-- end of deletion -->
</LinearLayout>
</RelativeLayout>

here you are setting click pending intent for the appwidgetId, but that should be view id.
RemoteViews views = new RemoteViews(context.getPackageName(),
R.layout.widget_layout);
views.setOnClickPendingIntent(appWidgetId, pendingIntent);
like:
if the id of a Button is R.id.button1. which is in widget layout if you want to set click listener to that button. then that should be like this :
RemoteViews views = new RemoteViews(context.getPackageName(),
R.layout.widget_layout);
views.setOnClickPendingIntent(R.id.button1, pendingIntent);

Related

How to make cardview responsive?

]2]2
this is NamazActivity.java In java class i just add cardview click listener and open a toast message. Every click listener shows the iteam ID with simple text
package com.example.shakeelmughal.assanislam;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.CardView;
import android.view.MenuItem;
import android.view.View;
import android.widget.GridLayout;
import android.widget.Toast;
public class NamazActivity extends AppCompatActivity {
GridLayout gridLayout;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_namaz);
//back button
if(getSupportActionBar()!= null)
{
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
gridLayout = findViewById(R.id.gridlayout);
setSingleClick(gridLayout);
}
//function for going back to previous activity
#Override
public boolean onOptionsItemSelected(MenuItem item) {
if(item.getItemId() == android.R.id.home)
finish();
return super.onOptionsItemSelected(item);
}
private void setSingleClick(GridLayout gridLayout) {
for (int i = 0; i < gridLayout.getChildCount(); i++) {
CardView cardView = (CardView) gridLayout.getChildAt(i);
final int s = i;
cardView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Toast.makeText(NamazActivity.this, "Item " + s + " Clicked", Toast.LENGTH_SHORT).show();
}
});
}
}
}
this is nazamactivity.xml In XML class i use gridlayout and inside it i use cardview with a text view and a image view. I have make 3 card in it...
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.shakeelmughal.assanislam.NamazActivity"
android:orientation="vertical"
android:weightSum="5">
<RelativeLayout
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp">
<TextView
android:id="#+id/textGrid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="40sp"
android:textColor="#000"
android:layout_centerInParent="true"
android:text="نماز"/>
</RelativeLayout>
<GridLayout
android:id="#+id/gridlayout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_alignParentTop="true"
android:layout_weight="4"
android:alignmentMode="alignMargins"
android:columnCount="1"
android:columnOrderPreserved="false"
android:padding="14dp"
android:rowCount="3">
<!-- Row 1 -->
<!-- Col 1 -->
<android.support.v7.widget.CardView
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_columnWeight="1"
android:layout_marginBottom="15dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_rowWeight="1"
app:cardCornerRadius="8dp"
app:cardElevation="8dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center_vertical"
android:layout_margin="16dp"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:src="#drawable/tahart"
android:paddingRight="70dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text= " Ùرض نمازیں"
android:textAlignment="center"
android:textColor="#000"
android:textSize="25sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="25sp"
android:textColor="#000"
android:text="5"
android:paddingLeft="10dp"/>
</LinearLayout>
</android.support.v7.widget.CardView>
<!-- Row 2 -->
<!-- Col 1 -->
<android.support.v7.widget.CardView
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_columnWeight="1"
android:layout_marginBottom="15dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_rowWeight="1"
app:cardCornerRadius="8dp"
app:cardElevation="8dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center_vertical"
android:layout_margin="16dp"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:src="#drawable/namaz"
android:paddingRight="70dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="واجب نمازیں"
android:textAlignment="center"
android:textColor="#000"
android:textSize="25sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000"
android:text="3"
android:textSize="25sp"
android:paddingLeft="10dp"/>
</LinearLayout>
</android.support.v7.widget.CardView>
<!-- Row 3 -->
<!-- Col 1 -->
<android.support.v7.widget.CardView
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_columnWeight="1"
android:layout_marginBottom="15dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_rowWeight="1"
app:cardCornerRadius="8dp"
app:cardElevation="8dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center_vertical"
android:layout_margin="16dp"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:paddingLeft="10dp"
android:paddingRight="80dp"
android:src="#drawable/namaz" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Ù†ÙÙ„ نمازیں"
android:textAlignment="center"
android:textColor="#000"
android:textSize="25sp"
android:paddingRight="20dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="4"
android:textSize="25sp"
android:textColor="#000"/>
</LinearLayout>
</android.support.v7.widget.CardView>
</GridLayout>
</LinearLayout>
Try this Make ScrollView as your parent layout it will work
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="5">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<TextView
android:id="#+id/textGrid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="نماز"
android:textColor="#000"
android:textSize="40sp" />
</RelativeLayout>
<GridLayout
android:id="#+id/gridlayout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_alignParentTop="true"
android:layout_weight="4"
android:alignmentMode="alignMargins"
android:columnCount="1"
android:columnOrderPreserved="false"
android:padding="14dp"
android:rowCount="3">
<!-- Row 1 -->
<!-- Col 1 -->
<android.support.v7.widget.CardView
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_columnWeight="1"
android:layout_marginBottom="15dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_rowWeight="1"
app:cardCornerRadius="8dp"
app:cardElevation="8dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center_vertical"
android:layout_margin="16dp"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:paddingRight="70dp"
android:src="#drawable/ic_message" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" Ùرض نمازیں"
android:textAlignment="center"
android:textColor="#000"
android:textSize="25sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:text="5"
android:textColor="#000"
android:textSize="25sp" />
</LinearLayout>
</android.support.v7.widget.CardView>
<!-- Row 2 -->
<!-- Col 1 -->
<android.support.v7.widget.CardView
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_columnWeight="1"
android:layout_marginBottom="15dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_rowWeight="1"
app:cardCornerRadius="8dp"
app:cardElevation="8dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center_vertical"
android:layout_margin="16dp"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:paddingRight="70dp"
android:src="#drawable/ic_message" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="واجب نمازیں"
android:textAlignment="center"
android:textColor="#000"
android:textSize="25sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:text="3"
android:textColor="#000"
android:textSize="25sp" />
</LinearLayout>
</android.support.v7.widget.CardView>
<!-- Row 3 -->
<!-- Col 1 -->
<android.support.v7.widget.CardView
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_columnWeight="1"
android:layout_marginBottom="15dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_rowWeight="1"
app:cardCornerRadius="8dp"
app:cardElevation="8dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center_vertical"
android:layout_margin="16dp"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:paddingLeft="10dp"
android:paddingRight="80dp"
android:src="#drawable/ic_message" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="20dp"
android:text="Ù†ÙÙ„ نمازیں"
android:textAlignment="center"
android:textColor="#000"
android:textSize="25sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="4"
android:textColor="#000"
android:textSize="25sp" />
</LinearLayout>
</android.support.v7.widget.CardView>
</GridLayout>
</LinearLayout>
</ScrollView>

getText() returns empty string (android studio)

I have a little question here about android development.
I already searched on internet, but i still can't find the solution.
I want to getText() from a view, but it just returns an empty ("") string.
Here's my .java code:
public void kotakCentang(View view)
{
RelativeLayout vwParentRow = (RelativeLayout)view.getParent();
TextView id_test = (TextView)vwParentRow.getChildAt(0);
TextView nama_test = (TextView)vwParentRow.getChildAt(1);
tugas_status = (TextView)vwParentRow.getChildAt(5);
tanggalKasih = (EditText)vwParentRow.getChildAt(6);
tanggalKumpul = (EditText)vwParentRow.getChildAt(8);
waktuKasih = (EditText)vwParentRow.getChildAt(7);
waktuKumpul = (EditText)vwParentRow.getChildAt(9);
tugasKompleksitas = (EditText)vwParentRow.getChildAt(10);
Tugas tugas = new Tugas();
TugasRepo tugass = new TugasRepo(this);
tugas.nama = nama_test.getText().toString();
tugas.waktuDikasih = waktuKasih.getText().toString();
tugas.waktuDikumpul = waktuKumpul.getText().toString();
tugas.tanggalDikasih = tanggalKasih.getText().toString();
tugas.tanggalDikumpul = tanggalKumpul.getText().toString();
tugas.kompleksitas=Integer.parseInt(tugasKompleksitas.getText().toString());
tugasKompleksitas.getText().toString();
}
The getText() which returns empty string is just the tugas.waktuDikasih, and tugas.waktuDikumpul .
Thank you for your help.
----- UPDATE XML ----
here's my xml file:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/tugas_id"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#id/judul_tugas"
android:visibility="gone"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="judul tugas"
android:id="#+id/tugas_judul"
android:textSize="20dp"
android:layout_marginStart="60dp"
android:layout_marginTop="17dp"
android:layout_below="#+id/tugas_id"
/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/status_kerja"
android:checked="false"
android:textSize="10dp"
android:layout_alignTop="#+id/tugas_judul"
android:layout_toStartOf="#+id/button"
android:onClick="kotakCentang"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/colorPrimaryDark"
android:layout_below="#+id/status_kerja"
android:layout_alignParentStart="true"
android:layout_marginTop="19dp"
android:id="#+id/textView2">
</View>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Detil"
android:id="#+id/button"
android:layout_alignParentEnd="true"
android:textSize="10sp"
android:layout_marginEnd="16dp"
android:layout_alignTop="#+id/status_kerja"
android:layout_above="#+id/textView2"
android:onClick="detilTugas"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="status"
android:id="#+id/status_tugas"
android:layout_alignBottom="#+id/tugas_judul"
android:layout_toEndOf="#+id/tugas_id" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="date"
android:ems="10"
android:id="#+id/tanggal_diberikan"
android:text="Tanggal Diberikan"
android:textColor="#000000"
android:visibility="gone"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="time"
android:ems="10"
android:id="#+id/waktu_diberikan"
android:layout_below="#+id/tanggal_diberikan"
android:layout_alignStart="#+id/tanggal_diberikan"
android:layout_alignEnd="#+id/tanggal_diberikan"
android:text="Waktu diberikan"
android:textColor="#000000"
android:visibility="gone"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="date"
android:ems="10"
android:id="#+id/tanggal_kumpul"
android:text="Tanggal dikumpulkan"
android:layout_below="#+id/tugas_judul"
android:layout_alignStart="#+id/waktu_diberikan"
android:layout_alignEnd="#+id/waktu_diberikan"
android:textColor="#000000"
/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="time"
android:ems="10"
android:id="#+id/waktu_dikumpulkan"
android:layout_below="#+id/tanggal_kumpul"
android:layout_alignStart="#+id/tanggal_kumpul"
android:layout_alignEnd="#+id/tanggal_kumpul"
android:text="Waktu dikumpulkan"
android:textColor="#000000"
android:visibility="gone"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="time"
android:ems="10"
android:id="#+id/isi_kompleksitas"
android:text="Kompleksitas"
android:textColor="#000000"
android:editable="false"
android:visibility="gone"/>
<!--<TextView-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"-->
<!--android:text="id_tugas"-->
<!--android:id="#+id/tugas_id"-->
<!--android:layout_alignBottom="#+id/status_kerja"-->
<!--android:layout_alignEnd="#+id/tugas_judul"-->
<!--android:layout_marginEnd="117dp" />-->
</RelativeLayout>

How to set list view height programatically in android

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

list activity onListItemClick does not firing

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

How to make the popup window BG blur

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

Categories