how to make entire view in dialog clickable? - java

i have dialog and text inside eache view that i can click on .
i want all the view to be clickable insted only the text .
the code :
final Dialog dialog = new Dialog(List_Lists.this);
dialog.setContentView(R.layout.dialog_edit_tables);
dialog.setTitle("Action for " + table);
TextView delete = (TextView) dialog
.findViewById(R.id.tvDeleteTable);
TextView cancel = (TextView) dialog.findViewById(R.id.tvCancel);
OnClickListener l = new OnClickListener() {
#Override
public void onClick(View v) {
dbAdapter = new DBmethods(getApplicationContext());
switch (v.getId()) {
case R.id.tvDeleteTable:
viewListsAdapter.listsV.remove(pos);
dbAdapter.deleteTable(table);
break;
case R.id.tvCancel:
dialog.dismiss();
break;
case R.id.bTableRenameName:
if(dbAdapter.checkTableNameOK(List_Lists.this ,newName.getText().toString())){
viewListsAdapter.listsV.remove(pos);
viewListsAdapter.listsV.add(pos, newName.getText().toString().trim());
dbAdapter.renameTable(table , newName.getText().toString().trim());
renamedialog.dismiss();
};
break;
default:
break;
}
// if button is clicked, close the custom dialog
dialog.dismiss();
lv.invalidateViews();
}
};
delete.setOnClickListener(l);
cancel.setOnClickListener(l);
dialog.show();
}
});
}
as i said this code work fine if user press on text inside the view , but the empty view obviously wont respond . thanks !
if user press on red spot it activate the enter , if green than duplicate and so on...the current status is u have to press on the word , if u press on the colored spots it will do nothing

If im not wrong you need this to make layout clickable
try something like this
You can add a OnClickListener on it :
//onCreate
LinearLayout layout = (LinearLayout) findViewById(R.id.LinearLayout01);
layout.setOnClickListener(yourOnClickListener);
Should be working ;)

create an id of your dialog_edit_tables
let say android:id=#+id\testing in your xml.
now write this
LinearLayout yourlayout = (LinearLayout) findViewById(R.id.testing);
yourlayout.setOnClickListener(l);
hope this will help.

You haven't shown the XML layout but setting the width of the clickable text view to fill_parent should work, also make sure your parent layout also has the width set to fill_parent.
The onClickListener is not based on the text it is based on the actual component, therefore it looks as if the layout_width attribute is set to wrap_content, so the component is only then length of the text, therefore only where the text is, is clickable. Hope this makes sense.

If I am not wrong than you are using listview or tableview to display the text.
You can do one thing. Make the textview layout_width as fill_parent That way you will able to get the touch on the place that you marked.
Hope this will help.

Related

Android - Click through a TextView when not long-pressing (selecting) the TextView

What I'm trying to achieve is have a TextView inside of a CardView (that's in a RecyclerView) be selectable only when you long-press the TextView. And if you don't long-press the TextView, it is ignored and the input (click) is passed on to the parent (CardView) which has it's own event to do when pressed.
I've tried one solution where I add a "OnLongClickListener" to the TextView and enable "selectable" when triggered. However when you short-press the TextView, it blocks the input from reaching the parent CardView, which prevents the CardView from performing it's action, which is expanding the CardView.
textView.setOnLongClickListener(new View.OnLongClickListener() {
#Override
public boolean onLongClick(View v) {
textView.setTextIsSelectable(true);
return true;
}
});
I'm trying to find a solution to have the TextView be essentially ignored and pass the input to it's parent when it isn't long-pressed. Anyone have any ideas on how to achieve this?
I've looked here already: TextView selectable just on long click
Just write textView.setTextIsSelectable(true);
Remove onLongClick event, When you long press on Textview then it auto select textview text

How to refresh layout/context from list adapter (I think this is what i need)

Im having a bug that i cant understand the reason and how to resolve it. I belive that is a problem of layout/view/context refresh but i dont know.
I have a cell from a listView(I prefer recyclerView but the project has years) and in the corner of the cell i have a button to show more options. Programatically it just make an element View.GONE and another element View.VISIBLE.
I will attach code in a moment
To this button i setted too a listener that when i tap on it it do the opposite of below mentioned. It shows some elements and hide an entire LinearLayout from the cell. The elements are showed BUT the LinearLayout keeps on the screen like bugged. If i tap anywhere it disappears and if i try to tap on it it disappears too. Its like the view of that linear got bugged and keep in there like a ghost view. I will shop some pictures.
The cell normally at the beginning: https://imgur.com/1BjK0KP
The cell after i press the entire view to show the LinearLayout at the bottom of the cell: https://imgur.com/eONSptW
The cell after i press the arrow of the corner to hide the LinearLayout. Here it shows the view bugged https://imgur.com/jrT0qxV
The cell after i tap anywhere else https://imgur.com/XD1jN7U
public void expandView(View view){
final View cellView = view;
final LinearLayout editLinear = (LinearLayout) view.findViewById(R.id.cart_edit);
editLinear.setVisibility(View.VISIBLE);
final TextViewFont countText = (TextViewFont) view.findViewById(R.id.itemCount);
countText.setVisibility(View.GONE);
final TextViewFont total = (TextViewFont) view.findViewById(R.id.itemTotal);
final ImageView imageViewArrow = (ImageView) view.findViewById(R.id.cart_edit_image);
imageViewArrow.setImageDrawable(context.getResources().getDrawable(R.drawable.icon_arrow_up));
//notifyDataSetChanged();
imageViewArrow.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
countText.setVisibility(View.VISIBLE);
editLinear.setVisibility(View.GONE);
imageViewArrow.setImageDrawable(context.getResources().getDrawable(R.drawable.icon_arrow_down));
}
});
First of all, you don't need to store context because in View you have the method view.getContext().
I recommend this article:
https://possiblemobile.com/2013/06/context/
On the other hand, ensure that you don't have a ghost view that is overlapping your image view.

Android: Programmatically set checkbox set text position on the right

How can I set a programmatically created checkbox's text to be aligned on the left instead of right side of the checkbox. Below is a code snippet:
Checkbox check1 = new Checkbox(getApplicationContext());
check1.setLayoutParams(new ActionBar.LayoutParams(LinearLayoutCompat.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
check1.setId(fieldNo);
check1.setTextColor(Color.BLACK);
check1.setGravity(Gravity.RIGHT);
check1.setText(formField.get(fieldNo));
The above code resulted in the text shown on the right of the checkbox.
Here is a screenshot :
How can I have the text on the left of the checkbox?
You need to change the following
check1.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
In this line you were using ActionBar params and then LinearLayoutCompat params. Try to stick to 1 category and in custom views like checkbox just LinearLayout would do.
UPDATE 1:
You should use CheckedTextView. I have used standard android drawable for that but you can also use your custom Check box design as well.
So your overall code would look like -
final CheckedTextView check1 = new CheckedTextView(getApplicationContext());
check1.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
check1.setId(fieldNo);
check1.setCheckMarkDrawable(android.R.drawable.checkbox_off_background);
check1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (check1.isChecked()){
check1.setChecked(false);
check1.setCheckMarkDrawable(android.R.drawable.checkbox_off_background);
}else{
check1.setChecked(true);
check1.setCheckMarkDrawable(android.R.drawable.checkbox_on_background);
}
}
});
check1.setTextColor(Color.BLACK);
check1.setGravity(Gravity.LEFT);
check1.setText(formField.get(fieldNo));

How to display drop-down list-view below particular view in android?

I have one filter button.I need to open expandable/dropdown filter same as given below image.I tried popup menu and Listpopup window but,I did not get any success.
Thanks in advance
you can make use of fragment which will be below the filter button,layout will include the ui you expect i.e upper arrow and expandable view or any view you are using..
After clicking on filter just visible the fragment and with fragment transition,for the effect you can use animation too...
This i already done,you can refer carwale app used car section..click on filter button one same dilog will come..
for any thing let me know further..
I did code by the help of above comments. but the code looks as below.
final View popUpView = getLayoutInflater().inflate(R.layout.exp, null);
listPopupWindow = new PopupWindow(popUpView, LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT, true);
expandableListView= (ExpandableListView) popUpView.findViewById(R.id.expandableListView);
btnticker.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
expandableListDetail = ExpandableListDataPump.getData();
expandableListTitle = new ArrayList<String>(expandableListDetail.keySet());
expandableListAdapter = new CustomExpandableListAdapter(MainActivity.this, expandableListTitle, expandableListDetail);
expandableListView.setAdapter(expandableListAdapter);
listPopupWindow.showAsDropDown(v);
}
});

Empty ListView show another activity

I am making an application which uses ListView to show DB elements. But in the first opening or when user will delete everything DB will be empty and then ListView will show blank screen. I want to show a message when it happens. Not only TextView but also Button. For example "DB now empty. Click on button and try to add some records". ListView 's setEmptyView method allows to add only TextView . Is it really possible to create a layout and show it when ListView is empty?
You can use the property setEmptyView.
If the list is empty and your desired display.
ListView listView = (ListView) findViewById(R.id.lst);
View child = getLayoutInflater().inflate(R.layout.empty_view, null);
((ViewGroup)listView.getParent()).addView(child);
listView.setEmptyView(child);
You can dynamically add a button in the activity layout if your list is empty.
Set onClickListner on the button and override the onClick().
Refer below code:
LinearLayout linear = (LinearLayout)findViewById(R.id.layout);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
Button btn = new Button(this);
btn.setId("btnDynamic");
btn.setText("Go to create entry page");
linear.addView(btn, params);
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Toast.makeText(view.getContext(),
"Button clicked index = " + id_, Toast.LENGTH_SHORT)
.show();
}
});
Let me know if this helps.
You can pre-define a layout containing text view and and button as you stated in your question and set it's visibility = gone in your xml or in java code. When the List View will be empty you can set visibility the visibility of the listview.setVisibility(View.GONE) and set your's layout (containing button and a textview) layout.setVisibility(View.VISIBLE)

Categories

Resources