I searched lot on internet to find a solution for my problem but I haven't found a answer. I hope someone can help me.
I have a Android application where I made a fragment with 3 tabs. Every tab had a different layout and in every layout there is a listview with different id. The problem is that, when i click on item of listview, only the item of the first tab take focus and background was set to green. In the other tabs the item is selected but focus don't change the background item color.
I had clear the focus on the first tab if was selected but this don't resolve the problem.
this is the code that I implementer on tab
listView.setAdapter(adapter);
listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
listView.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> arg0, View view,
int pos, long arg3) {
view.setSelected(true);
selectedBusiness = businessList.get(pos);
buttonModify.setEnabled(true);
}
});
Any idea?
Thank Max
I found the solution.
The error in my case was made from
ArrayAdapter adapter = new ArrayAdapter(getActivity(), R.layout.my_business_item);
I don't know why but the problem was the layout. In the other two tabs, I used the adapter with another layout android.R.layout.simple_list_item_1. With this layout the focus dosen't work. With my simple layout it works.
Related
I'm stuck while importing twowayview as module to my project.
.
Next button is not getting enabled, is it the correct way to do it, or there is another way.
please help.
I guess wanting to import the library TwoWayView is because you want to create lists and horizontal and vertical grids. If so I recommend you use the called RecyclerView, that can do everything you do with TwoWayView, i.e. can create lists and grids in horizontally and vertically.
Here you can get information about RecyclerView use in horizontal and vertical:
http://www.androidhive.info/2016/01/android-working-with-recycler-view/
Also I have to say I had some bugs with the code shown on the page AndroidHive.
It turns out that in the onCreate() method of MainActivity.java the method that is called prepareMovieData() is declared in last place, when it should be called right after declaring RecyclerView, ie, right after this line:
recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
If this call is declared it in last place, a mistake appear that the object that we created (in the case of AndroidHive is the Movies class) will appear this to null, ie, it has no data.
Moreover, at the end of prepareMovieData() method the following line states:
mAdapter.notifyDataSetChanged();
For me personally, this line failure in the application that causes the App is closed, eliminating this code works perfectly provoked me. Actually, not that it serves this line, but I would appreciate if anyone knows why, to edit this entry explaining it.
Finally, if the intent of this post was to create a RecyclerView horizontally, then I leave the explanation for a RecyclerView is horizontal or vertical.
In the onCreate() method of file MainActivity.java we add a LayoutManager to RecyclerView with the following lines:
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext());
recyclerView.setLayoutManager(mLayoutManager);
This Layout Manager is responsible to tell the RecyclerView as the data that we introduce will be displayed, ie, if the content is vertically, horizontally, in a list, etc .. So if our list is displayed horizontally only we need to edit the above lines by the following:
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext(), LinearLayoutManager.HORIZONTAL, false);
recyclerView.setLayoutManager(mLayoutManager);
If you want the list vertically, we leave the lines as they are.
Hope this can help you.
I am trying to develop an app with MonoTouch. For some screens I create the UI in code. I have a dynamically created RadioGroup with normally two to four RadioElements (choices). Sometimes the text (dynamic too) is too long for the RadioElement so that on an iPhone the text gets shorted by ... at the end.
I have googled and found no suggestion on how to create multiline RadioElements. I know you can create a MultilineElement if you want text over several lines, but how would I go about combining the two? I assume I have to inherit from RadioElement and override some events, but which? Is it the MonoTouch.UIKit.UITableViewCell GetCell (MonoTouch.UIKit.UITableView tv) event?
Alternatively, how would you go about creating a MultilineElement that get a check mark on it when it got pressed/selected?
Or should I be thinking completely different? Are there some other components that could solve this in a simpler way?
This is a sort-of solution (at least it solves my problem):
public class MultilineRadioElement : RadioElement
{
public MultilineRadioElement (string caption, string group)
: base(caption, group) { }
public override MonoTouch.UIKit.UITableViewCell GetCell
(MonoTouch.UIKit.UITableView tv)
{
var cell = base.GetCell (tv);
cell.TextLabel.Lines = 2;
return cell;
}
}
When I now use a MultilineRadioElement instead of a RadioElement the text shows on two lines. For me two lines are enough. If the text is even longer and you still want to fit it inside the RadioElement at its current size you will probably have to calculate the size of the text and for example set the font in cell.TextLabel.Font to a more appropriate font.
I don't know how to make the RadioElement itself get bigger, so this is my best suggestion.
By the way, you should probably also add
protected override MonoTouch.Foundation.NSString CellKey
{
get { return base.CellKey; }
}
to the MultilineRadioElement as the intellisense in my Xamarin Studio suggests that this should be done when overriding GetCell, although it seems to work without it as well.
I am very happy if someone has an even better suggestion!! (yes, two exclamation marks :) )
The layout of my spinner while close is adopting the layout of the layout configured to each row of the spinner.
The layout for each row is defined inside getCustomView method because I am using a custom adapter to the spinner, here it is define:
public View getCustomView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater=getLayoutInflater();
View row=inflater.inflate(R.layout.row, parent, false); //here is the layout for each row -> R.layout.row
//there are more things here but doesnt matter for the question..
}
On that layout (row.xml) I have margins top and bottom, because I want to give soem space between the choices.. But then the button itself of the spinner, I mean, the layout of the spinner while closed also has the margins.. and it looks larger than what I want.
It is possible to define different layouts?
I tryed to make the spinner layout at xml using less height, but then I can see the option clearly.. because it has margins..
Did I make myself clear?
Thanks alot in advance.. If someone didnt understand I can explain better.
Thanks ;)
Finnaly found a solution to this problem :)
Didn't know that getDropDownView was for the dropdown layout and the getView was for the single layout, at closed spinner...
Solution here: Android Spinner with different layouts for "drop down state" and "closed state"?
I want to create a JavaFX table that, in the cells of one column, allows the user to edit XHTML text. I only need very basic formatting capabilities like bold, italic, striketrough.
I have already managed to implement this by using my own subclass of TableCell and using a WebView for each cell (HTMLEditor would of course have been another choice, but my guess is that for my requirements, WebView should be sufficient).
However, to make editing comfortable for the user, I need the following features:
1. The cell height needs to resize if the user enters multi-line text.
2. A context menu (or, if not possible, some other menu or button) should allow formatting parts of the text in a cell as described above (bold, italic..)
Has anybody been successful in implementing something similar ? I have seen suggestions on the web, but they rarely included code samples.
I have succedded doing something similar.
I figured I can share some of the basic clues that allowed me to achieve it.
Resize the whole WebView. For that, the whole WebView must be an editable html page. You achive that by setting contenteditable to true:
<body contenteditable='true' id='content'></body>
You can have a context menu over a webview. But it is something tricky, as you must first disable the original context menu associated to it.
WebView editView;
...
EventDispatcher originalDispatcher = editView.getEventDispatcher();
editView.setEventDispatcher(new WebmenuEventDispatcher(originalDispatcher));
And this is the event dispatcher class:
public class WebmenuEventDispatcher implements EventDispatcher {
private EventDispatcher originalDispatcher;
public WebmenuEventDispatcher(EventDispatcher originalDispatcher) {
this.originalDispatcher = originalDispatcher;
}
#Override
public Event dispatchEvent(Event event, EventDispatchChain tail) {
if (event instanceof MouseEvent) {
MouseEvent mouseEvent = (MouseEvent) event;
if (MouseButton.SECONDARY == mouseEvent.getButton()) {
mouseEvent.consume();
// Show our own menu
cmEdit.show(editView.getScene().getWindow(), mouseEvent.getScreenX(), mouseEvent.getScreenY());
}
}
return originalDispatcher.dispatchEvent(event, tail);
}
}
Now, for setting the font from within that menu, you need a bidirectional Java<->javascript bridge and use some javascript in the webview side.
I have an activity that displays a layout. I would like to go to another layout on the click of a button within the same activity. After going to the next layout, I have to go to a third layout by clicking the button in second layout, that too from tha same activity. I have defined the buttons for each layout in their respective xml files with unique IDs. I am accessig the IDs of all the buttons of all the layouts from the same activity to define "onClick()".
When I define onClick() ofr all the buttons from the same activity, it gives me "NullPointerException" during rum time.
Could anyone give some help as how to accompilish all these things from the same activity?
OnCreate(Bundle icic){
setContentView(R.layout.first_xml);
((Button)findViewById(R.id.button_first).setOnclickListener(new onClickListener(){
secondLayout();
});
}
private void secondLayout(){
setContentView(R.layout.second_xml);
((Button)findViewById(R.id.button_second).setOnclickListener(new onClickListener(){
thirdLayout();
});
}
private void thirdLayout(){
setContentView(R.layout.third_xml);
((Button)findViewById(R.id.button_third).setOnclickListener(new onClickListener(){
// do work...
});
}
But this is not the solution to use code like above... Instead you can use Dialog to achieve your goal......enter code here