Grid item not clickable - android

I have used one gridview calendar in my application.The gridview calendar is working correctly and displayed the element what i want.My problem is when i click the grid item this will not be clickable.Thanks
My Gridview:
<LinearLayout
android:id="#+id/gridlayoutid"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<GridView
android:id="#+id/gridviewid"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:horizontalSpacing="-1px"
android:numColumns="7"
android:stretchMode="columnWidth"
android:textDirection="anyRtl" />
</LinearLayout>
My Grid Rows:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="200dp"
android:layout_height="fill_parent"
android:background="#drawable/gridcal"
android:orientation="vertical">
<TextView
android:id="#+id/griddate"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="10dp"
android:paddingBottom="10dp"
android:textColor="#color/text_color"
android:textSize="14sp"
android:textStyle="bold" >
<!-- android:layout_height="200dp" -->
</TextView>
<TextView
android:id="#+id/gridstatus"
android:layout_gravity="right"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
My Activity:
gridview = (GridView) view.findViewById(R.id.gridviewid);
gridview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v,
int position, long id) {
//some codes
}
}
}
});

Related

how fix when i click on the twelve item from gridview

i have a problem, all items before the number twelve is ok, but starting on twelve when i click on that item and the next items return open the new activity but with other position , i mean when i click on the item number twelve , return me the value number three.
this is my code
public void onItemClick(AdapterView<?> arg0, View arg1, int position,
long arg3) {
// TODO Auto-generated method stub
objAllBean=arrayOfLatestVideo.get(position);
int pos=objAllBean.getId();
Intent intplay=new Intent(getActivity(),VideoPlay.class);
intplay.putExtra("POSITION", pos);
intplay.putExtra("VIDEO_ID", allArrayVideo);
intplay.putExtra("VIDEO_CATNAME", allArrayVideoCatName);
intplay.putExtra("VIDEO_CATID", allArrayVideoCatId);
intplay.putExtra("VIDEO_URL", allArrayVideourl);
intplay.putExtra("VIDEO_NAME", allArrayVideoName);
intplay.putExtra("VIDEO_CID", allArrayVideoId);
intplay.putExtra("VIDEO_DURATION", allArrayVideoDuration);
intplay.putExtra("VIDEO_DISCRIPTION", allArrayVideoDesc);
intplay.putExtra("VIDEO_IMAGE_URL",allArrayImageUrl);
startActivity(intplay);
}
Layout Grid
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/gradient"
android:gravity="center"
android:id="#+id/rootlayout"
android:orientation="vertical" >
<GridView
android:id="#+id/lsv_latest"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numColumns="#integer/columns" <-- 3
android:verticalSpacing="0dp"
android:horizontalSpacing="0dp"
android:clickable="true"
android:stretchMode="columnWidth">
</GridView>
</FrameLayout>
item gridview
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/gradient"
android:paddingTop="5dp"
android:paddingRight="3dp">
<ImageView
android:id="#+id/picture"
android:src="#drawable/ic_launcher"
android:contentDescription="#string/desc"
android:layout_width="match_parent"
android:layout_height="170dp"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginLeft="5dp">
<TextView
android:id="#+id/text_category"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textColor="#ffffff"
android:background="#009ACC"
android:padding="2dp"
android:layout_marginTop="4dp"
android:textSize="10dp"
/>
<TextView
android:id="#+id/second"
android:text=""
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:textSize="1dp"
/>
<TextView
android:id="#+id/text"
android:text="HD"
android:layout_width="wrap_content"
android:layout_gravity="bottom"
android:layout_marginTop="120dp"
android:background="#9a000000"
android:layout_height="22dp"
android:ellipsize="end"
android:maxLines="1"
android:textColor="#android:color/white"
/>
</LinearLayout>
</FrameLayout>

Unable to set image to android gridview.setEmptyView

I have written a grid view that is working fine.
I need an image when gridview is having no item.
I tried to add it like
gridView.setEmptyView((ImageView)findViewById(R.drawable.empty));
empty.png is the image in the res/drawable
but imageView is not getting showed when grid View is empty.
The full code
oncreate
setContentView(R.layout.main_activity);
GridView gridView = (GridView) findViewById(R.id.listhabbit_ma);
gridView.setEmptyView((ImageView)findViewById(R.drawable.empty));
habbitListAdapter = new HabbitListAdapter(AppManager.getHabbits());
gridView.setAdapter(habbitListAdapter);
habbitListAdapter.notifyDataSetChanged();
gridView.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent(MainActivity.this, HabbitDetail.class);
intent.putExtra("position", position);
startActivityForResult(intent, habbit_delete);
main.xml
<GridView
android:id="#+id/listhabbit_ma"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:numColumns="2"
android:verticalSpacing="8dp"
android:horizontalSpacing="8dp"
android:stretchMode="columnWidth"
android:gravity="center"
android:layout_weight="1"
android:paddingBottom="3dp"
android:paddingTop="3dp">
</GridView>
I am unable to figure out the error. Should I define a image view at the end of main.xml?
edit1
full layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="left"
android:orientation="vertical"
android:background="#color/background">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/user_profile"
android:orientation="horizontal"
android:layout_weight="0.07">
<TextView
android:id="#+id/textView1_ma"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:text="#string/user_name"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textView2_ma"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center|right"
android:text="#string/repotation"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<GridView
android:id="#+id/listhabbit_ma"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:numColumns="2"
android:verticalSpacing="8dp"
android:horizontalSpacing="8dp"
android:stretchMode="columnWidth"
android:gravity="center"
android:layout_weight="1"
android:paddingBottom="3dp"
android:paddingTop="3dp">
</GridView>
<Button
android:id="#+id/add_habbit_button_ma"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="#color/user_profile"
android:onClick="onAddButtonClick"
android:text="Add new Habbit"
android:layout_weight="0"/>
</LinearLayout>
You are not doing it right. Image != ImageView. The proper way, for example, is the following (very simplified):
ImageView iView = new ImageView(mContext);
//set layout params if needed
iView.setImageResource(R.drawable.empty);
((ViewGroup)gridView.getParent()).addView(iView);
gridView.setEmptyView(iView);
You can also declare it at your XML layout as #VipulPatel shown
Following layout and code works fine :
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<GridView
android:id="#+id/listhabbit_ma"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:numColumns="2"
android:verticalSpacing="8dp"
android:horizontalSpacing="8dp"
android:stretchMode="columnWidth"
android:gravity="center"
android:layout_weight="1"
android:paddingBottom="3dp"
android:paddingTop="3dp">
</GridView>
<TextView
android:id="#+id/empty_list_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="List view is empty"
android:visibility="gone" />
</LinearLayout>
Code :
GridView gridView = (GridView) findViewById( R.id.listhabbit_ma );
TextView tvNoDataFound = (TextView) findViewById(R.id.empty_list_view);
tvNoDataFound.setVisibility(View.VISIBLE);
gridView.setEmptyView( findViewById( R.id.empty_list_view ) );

CursorAdapter onitemClick of listview

Hi I am developing an android app with CursorAdapter for loading the listview. onItemClick of the listview item, I am trying to start a dialogue activity.
adapter = new ConversationAdapter(MainActivity.this, cursor);
list.setAdapter(adapter);
list.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> parent, View view, int position, long arg3)
{
Cursor cur = (Cursor) adapter.getItem(position);
cur.moveToPosition(position);
id = cur.getString(cur.getColumnIndexOrThrow("_id"));
Intent intent = new Intent(MainActivity.this, DialogueActivity.class);
Bundle bundle = new Bundle();
bundle.putString ("id", id);
intent.putExtras(bundle);
startActivity(intent);
}
});
I am using only the startActivity without a finish(). The problem is the listview which is to be displayed at back disappears and there is just a black screen. Not sure what I need to do so that listview is displayed in background of DialogueActivity.
onItemClick of the listview item is displayed as below
main_activity.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".EaseSms" >
<LinearLayout
android:id="#+id/linearlayoutlistSMS"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".88"
android:orientation="vertical"
android:paddingBottom="3dp" >
<ListView
android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:cacheColorHint="#00000000"
android:divider="#000000"
android:dividerHeight="5dp" >
</ListView>
<TextView
android:id="#+id/Nosms"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="No SMS to display"
android:textColor="#FFFFFF"
android:textSize="28dp"
android:textStyle="bold"
android:visibility="gone" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayoutCreateMessage"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".12"
android:gravity="center"
android:orientation="horizontal" >
<LinearLayout
android:id="#+id/createmsg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/newcreatesms"
android:gravity="center"
android:orientation="horizontal" >
</LinearLayout>
</LinearLayout>
and dialogue_activity.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/linearLayoutdeleteall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight=".33"
android:background="#drawable/cal_sms_bg"
android:gravity="center|left"
android:orientation="vertical"
android:paddingTop="5dp" >
<ImageView
android:id="#+id/edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#null"
android:src="#drawable/newdeleteconversation"
android:visibility="visible" />
</LinearLayout>
</LinearLayout>
please Help. Thanks!
Try this codes..
getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
before setContentView(R.layout.activity); in DialogueActivity.class

OnItemClickListener not work

I have a listview. And i need do click in each element inside listview. But the onItemClickListener don't work. I try put each textView with focusable="false" and put android:descendantFocusability="blocksDescendants" but nothing works and i don't know where is my error.
Here is my code
xml of each element inside listview
**xml_item_list**
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
android:paddingTop="5dip"
android:paddingBottom="8dip"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeight"
android:background="#android:drawable/list_selector_background"
android:clickable="true"
android:longClickable="true"
android:descendantFocusability="blocksDescendants">
<TextView
android:id="#+id/lDate"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_marginRight="3dp"
android:background="#drawable/et_style"
android:gravity="center"
android:textColor="#c2c2c2"
android:textAppearance="?android:attr/textAppearanceMedium"
android:focusable="false" />
<TextView
android:id="#+id/lDescription"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
android:layout_weight="1"
android:gravity="center"
android:background="#drawable/et_style"
android:textColor="#c2c2c2"
android:textAppearance="?android:attr/textAppearanceMedium"
android:focusable="false"/>
<TextView
android:id="#+id/lMissValue"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:gravity="center_horizontal|center"
android:layout_gravity="center"
android:textColor="#DDCC2EFA"
android:textAppearance="?android:attr/textAppearanceMedium"
android:focusable="false"/>
</TableRow>
**main_xml_list**
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/background_tile"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginBottom="50dp">
<ImageView
android:id="#+id/bankTransaction"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"/>
<TextView
android:id="#+id/contextLabel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/et_style"
android:textSize="28dp"
android:layout_gravity="bottom" />
</LinearLayout>
<ListView
android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants">
</ListView>
</LinearLayout>
Code inside onCreate() function of activity
onCreate()
listView = getListView();
listView.setClickable(true);
listView.setOnItemClickListener(
new OnItemClickListener()
{
#Override
public void onItemClick(AdapterView<?> arg0, View view,int position, long id) {
Log.w(TransactionView.class.getName(), "Item click listener");
Toast.makeText(TransactionView.this, "Item clicado", Toast.LENGTH_LONG).show();
}
}
);
Anyone can help me?
Thanks for yout time.
try like this
lvlList = (ListView)findViewById(R.id.lvlList);
lvlList.setOnItemClickListener(new OnItemClickListener()
{
#Override
public void onItemClick(AdapterView<?> a, View v,int position, long id)
{
Toast.makeText(getBaseContext(), "Click", Toast.LENGTH_LONG).show();
}
});
First of all,check that you have added this line or not in your code.
public class MyActivity extends Activity implements OnItemClickListener
Then add this code in your onCreate() of activity ...
ListView listView = (ListView) findViewById(R.id.lisview);
listView.setOnItemClickListener(this);
#Override
public boolean onItemClick(AdapterView<?> parent, View v, int pos,long id)
{
System.out.println("~~~~~~Item Clicked");
return false;
}
change this ::
android:id="#+id/list"
Hope this helps :)
My Solution.....
public class TransactionView extends ListActivity implements **AdapterView.OnItemClickListener**{}
**onCreate()**{
adapter = new SimpleCursorAdapter(
this,
R.layout.transaction_item_view,
c,
new String[]{MySQLiteHelper.C_TRANSACTION_DUE, MySQLiteHelper.C_TRANSACTION_DESCRIPTION, MySQLiteHelper.C_TRANSACTION_VALUE, MySQLiteHelper.C_TRANSACTION_COVERVALUE, MySQLiteHelper.C_TRANSACTION_STATE, MySQLiteHelper.C_TRANSACTION_SOURCE},
new int[]{ R.id.lDate, R.id.lDescription, R.id.lMissValue},SimpleCursorAdapter.IGNORE_ITEM_VIEW_TYPE);
}
setListAdapter(adapter);
listView = getListView();
listView.setOnItemClickListener(new AdapterView.OnItemClickListener()
{
#Override
public void onItemClick(AdapterView<?> arg0, View view,int position, long id) {
Log.w(TransactionView.class.getName(), "Item click listener");
Toast.makeText(TransactionView.this, "Item clicado", Toast.LENGTH_LONG).show();
}
}
);
**item_list_row**
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
android:paddingTop="5dip"
android:paddingBottom="8dip"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeight"
android:background="#android:drawable/list_selector_background"
>
<TextView
android:id="#+id/lDate"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_marginRight="3dp"
android:background="#drawable/et_style"
android:gravity="center"
android:textColor="#c2c2c2"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
<TextView
android:id="#+id/lDescription"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
android:layout_weight="1"
android:gravity="center"
android:background="#drawable/et_style"
android:textColor="#c2c2c2"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
<TextView
android:id="#+id/lMissValue"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:gravity="center_horizontal|center"
android:layout_gravity="center"
android:textColor="#DDCC2EFA"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
**main_xml_list**
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/background_tile"
android:orientation="vertical" >
<ListView
android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</ListView>
</LinearLayout>

onListItemClick and CheckedTextView not respoding

I got ListActivity, each item has 2 textviews image and CheckedTextView. I am trying to implement simple multichoiselist...
I have two problems:
1.
#Override
protected void onListItemClick(android.widget.ListView l, View v,
int position, long id)
{
...
}
doesnt respond at all I have tried it with the debugger and when I press on any list item it doesnt stop there. and I have tried all kind of things (like focusable:false)
two:.
I cant toggle the CheckedTextView anyhow.
here is my xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="100sp"
android:focusable="false" android:focusableInTouchMode="false">
android:padding="6dip">
<ImageView android:layout_width="wrap_content"
android:layout_height="fill_parent" android:src="#drawable/icon"
android:id="#drawable/icon" android:layout_marginLeft="6dip"
android:focusable="false" android:focusableInTouchMode="false">
</ImageView>
<LinearLayout android:id="#+id/LinearLayout01"
android:orientation="vertical" android:layout_width="1sp"
android:layout_height="fill_parent" android:layout_weight="1"
android:focusable="false" android:focusableInTouchMode="false">
<TextView android:id="#+id/toptext" android:layout_weight="1"
android:gravity="center_vertical" android:text="OrderNum"
android:singleLine="true" android:layout_height="0dp"
android:layout_width="wrap_content" android:focusable="false"
android:focusableInTouchMode="false">
</TextView>
<TextView android:id="#+id/bottomtext" android:layout_height="wrap_content"
android:layout_width="wrap_content" android:focusable="false"
android:focusableInTouchMode="false" android:text="TweetMsg">
</TextView>
<TextView android:id="#+id/twittLocation"
android:layout_weight="1" android:text="location" android:singleLine="true"
android:layout_width="fill_parent" android:layout_height="0dip"
android:focusable="false" android:focusableInTouchMode="false">
</TextView>
<TextView android:layout_weight="1" android:id="#+id/twittLocationlink"
android:text="locationlink" android:gravity="fill_horizontal"
android:layout_width="fill_parent" android:layout_height="0dip"
android:focusable="false" android:focusableInTouchMode="false">
</TextView>
</LinearLayout>
<CheckedTextView android:id="#android:id/text1" android:text="Delete"
android:layout_width="wrap_content" android:layout_marginRight="2dp"
android:layout_height="fill_parent"
android:checkMark="?android:attr/listChoiceIndicatorMultiple"
android:focusable="false"></CheckedTextView>
</LinearLayout>
any idea what's the problem?
thanks.
In your ListView set android:descendantFocusability="beforeDescendants". This might help.
Try this code:
public class Sample extends ListFragment implements OnItemClickListener{
ListView list;
list.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
}
});
}
Sample code

Categories

Resources