cant see textview items is clicked or not - android

I have created the textview dynamically. My whole project is in white background so I made this textview background white. If I click one of the textview items it should take me to another activity. I got that output.
But my problem is I cant see Textview is clicked or not. I have done this through textview.setClickable(true). I can see if it is black background. can anyone help me please
Sorry I forgot to add, My textcolor is black

you have to implement onClickListener for that text field, for example:
yourTextField.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
});

Related

Android how to show hidden item only for one row on click

im trying to create a listView, that has an Button item on it.
I want to make this button clickable, so I did something like this code in Adapter, getView:
myButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Log.d("_myButton_Log", "ShowOnClick");
}
});
And now im trying to change the visibility parameter for my textView:
TextView myDesc = row.findViewById(R.id.my_desc);
myDesc.setVisibility(convertView.GONE);
I want to show this textView in only one row, after click this button.
Now I make that, the button is clickable for each rows but as you can see it's show only the Log. Im a newbie in the ListViews and buttons on it and im trying to get knowledge how to make it work, but for now I cannot find any help...
So im begging here for some help! :)
Anyway if you want me to use the OnItemClickListener it's not possible because im using it for another way.
Ok I found out an response for my question.
Everyone with this problem - just need to make a simple action for a button in list view in your adapter like:
myButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
TextView myPrice = row.findViewById(R.id.price);
Button myButton = row.findViewById(R.id.button);
myPrice.setVisibility(convertView.VISIBLE);
myButton.setVisibility(convertView.GONE);
}
});

Change View Text Color by code

Well, I developed a menu with eight Buttons for an App. So, every time the user clicks on in one of the buttons, such button changes its background. And I would would like to change its color as well. But I got now idea how, since setTextColor does not work with Views.
I'm using View because its part of onClick method that I override in order to achieve what I want. So, here go the code:
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
v.setBackgroundResource(R.drawable.degrade_menu);
}
So, how could I change the text color?
Cheers,
Cast your v to TextView and then set the text color. Do not forget to read color from resourse
((TextView)v).setTextColor(getResources().getColor(R.color.errorColor));
quick solution:
final Button button = (Button) findViewById(<id>);
button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
button.setTextColor(<color>);
}
};
better solution: use states
Cast the view to a button. Then you can use settextcolor

to add extra <Edittext> views on click of button

I used the following code but the editview layout appearing is in the bottom and i want it to get displayed on the top.
If anybody can please tell me what to do so that it get displayed on the top
private OnClickListener OnClick() {
// TODO Auto-generated method stub
return new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
EditText t = new EditText(getApplicationContext());
t.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
mLayout.addView(t);
}
};
}
mLayout.addView(t) will add the new view at the end of the layout. Try to use mLayout.addView(t, 0) to add it as the first view in the layout.
You should add the EditText in the layout by default, but with it's visibility set to android:visibility="gone". This will cause the EditText to be present, but not visible. The rest of your layout will adjust for the View not being there.
Then in your onClick change the visibility on the EditText to visible. This will cause your UI to update with the now visible EditText.
mLayout.addView(t, 0);
where 0 indicates the position within the layout.
See this.

Android Calculator Error

I have two questions:
How do I adjust the buttons in a table, like a normal calculator?
Whenever I click the 'equal' button the app is closing -Force
Close.
I think the problem comes from the int sum=0; whenever I use it at the equal place it gives the error.
code
use this code it may help
display.setText(sum+"");
because you have declared sum as int and setText property accepts CharSequence
For adjusting buttons, use TableLayout or RelativeLayout, where you can position buttons relatively to others.
Concerning second question, just change
display.setText(sum);
to
display.setText(String.valueOf(sum));
To make your calculator work at least a little bit change equal.setOnClickListener to this:
equal.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
display.setText(String.valueOf(counter+sum));
counter=0;
sum=0;
}
});

Android textView disappears when clicked

I have a TextView with the android:onClick attribute. When clicked, the TextView disappears. I don't want the TextView to disappear when clicked. Any ideas?
Edit:
<TextView android:id="#+id/textView1"android:text="Click Me!"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:onClick="processClick"
android:clickable="true"/>
http://i1179.photobucket.com/albums/x386/jenningsr2006/unclicked.png
http://i1179.photobucket.com/albums/x386/jenningsr2006/clicked.png
Edit
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.example);
TextView t = (TextView)findViewById(R.id.textView1111);
t.setOnClickListener(new OnClickListener()
{
#Override
public void onClick(View v)
{
// Do some job here
Toast.makeText(getApplicationContext(), "Clicked", Toast.LENGTH_SHORT).show();
}
});
Clicking it does the operation correctly, that's not the problem. When I "mousedown" on the TextView, it disappears, then reappears on "mouseup".
I thought I had the same problem but it turned out the textview was not dissapearing, rather the color was changing so that it was the same as the background color. Thus it appeared hidden but it really was there. You can set the clicked color of the text view by setting it's color state list resource
http://developer.android.com/guide/topics/resources/color-list-resource.html
Have you registered a method processClick? There is no need to do it this way. Remove the clickable property and also onClick property. More simple approach is to set onClick listener from the code, for example in onCreate method:
TextView text = (TextView) findViewById(textView1);
text.setOnClickListener(new OnClickListener()
{
#Override
public void onClick(View v)
{
// Do some job here
}
});
The view becomes clickable automatically when you set an on click listener. Good luck

Categories

Resources