I have single view layout with edit text and image. To display data in listview i am using arrayadapter . While entering value in Edit text in first row. The data gets repeated to another row in listview . How can i resolve this ?
View rowView = null;
try {
if (convertView == null) {
//inflating view.
rowView =
inflater.inflate(R.layout.list_single_view,null,false);
}
else
{
//Setting view if layout is already implemented.
rowView = convertView;
}
imageView = (ImageView)
rowView.findViewById(R.id.iv_activity_image_single);
//Facing issue here in editText . The entered text gets repeated
et_image_name = (EditText)
rowView.findViewById(R.id.txt_user_notes);
et_image_description = (EditText)
rowView.findViewById(R.id.txt_user_description);
//Loading image using universal image loader to imageView
if (equipmentPicturesList.get(position) != null) {
Constant.imageLoader.displayImage("file:///" +
equipmentPicturesList.get(position).toString(), imageView, Constant.options,
new SimpleImageLoadingListener());
}
else {
imageView.setBackgroundResource(R.drawable.ic_launcher);
}
}
catch (Exception e) {
Logger.loadStackTrace(e);
}
return rowView;
The EditText messes with the focus of whatever layout it is in. That can be a little tricky by itself, but in a ListView it causes all sorts of problems. But there is a way around that, it will work if you put the EditText inside the footer or header of the ListView with addHeaderView or addFooterView. The reason that it works in the header or footer is that the header and footer views are not recycled by the ListView. Alternatively you can call setHasTransientState() on the EditText to prevent it from being recycled even as a normal view inside the ListView.
But beware that turning off the view recycling - especially if you do it for multiple views - can impact performance and scrolling speed of the ListView.
Related
I'm trying to create a setup where I have a UICollectionView with a header on top, and then another supplementary view on the side. I can't just place the supplementary view outside of the collectionView because it shares space with the collectionView cells inside of the collectionView and I also want it to scroll with it. Here's how it should look:
I've been thinking, and one solution I can think of is making a big collectionView, with the supplementary side view and the view to the right as cells of it, with the header as its header. However, I've heard it's not great to put a collectionView inside of a collectionView, especially if the scrolling directions are the same, and I also want to dynamically load more cells as I scroll, so in that case I would have to dynamically keep resizing the cell.
Is this configuration possible, in an elegant manner? Thanks!
It is possible to achieve that . There is a easy way that set Frame of Supplementary View and add UIEdgeInsets in the left of SectionInset .
Code as follow :
flowLayout = new UICollectionViewFlowLayout (){
HeaderReferenceSize = new CGSize(50, 50),
SectionInset = new UIEdgeInsets (20,65,20,20),
ScrollDirection = UICollectionViewScrollDirection.Vertical,
MinimumInteritemSpacing = 10, // minimum spacing between cells
MinimumLineSpacing = 10 // minimum spacing between rows if ScrollDirection is Vertical or between columns if Horizontal
};
The custom UICollectionReusableView class :
public class Header : UICollectionReusableView
{
UILabel label;
public string Text {
get {
return label.Text;
}
set {
label.Text = value;
SetNeedsDisplay ();
}
}
[Export ("initWithFrame:")]
public Header (CGRect frame) : base (frame)
{
BackgroundColor = UIColor.Red;
label = new UILabel (){Frame = new CGRect (0,80,50,500), BackgroundColor = UIColor.Yellow};
label.Lines = 5;
AddSubview(label);
}
}
The effect :
Above code based on this official sample to modify .
I need to autocomplete textfields from tableview. How can i select the right textfield(where i am writing at this moment)?
code is here
If I understand correctly you have two UITextFields and a UITableView and when you tap on a cell in the table view you want to put it's text into whichever text field has your input focus.
Try this:
if firstTextField.isFirstResponder {
firstTextField.text = selectedCell.textLabel.text
}
if secondTextField.isFirstResponder {
secondTextField.text = selectedCell.textLabel.text
}
The isFirstResponder method tells you if the control has the current focus and only one of them can.
I have a webview containing some text. I need to be able to swipe on the webview and make text selection at the same time. The problem is after I have implemented the swipe overriding the onTouchEvent method, the other features of the webview seem to have freezed, links in the webview aren't clickable anymore, and the text selection (after longClick) doesn't work anymore, I need to make to implement the swipe and preserve the other features of the webview.
I tried to override the longClick click method as well and use the following method to implement text selection:
public void selectAndCopyText() {
try {
Method m = WebView.class.getMethod("emulateShiftHeld", null);
m.invoke(MyWebView.this, null);
}
catch (Exception e1) {
e1.printStackTrace();
KeyEvent shiftPressEvent = new KeyEvent(0,0,KeyEvent.ACTION_DOWN,KeyEvent.KEYCODE_SHIFT_LEFT,0,0);
shiftPressEvent.dispatch(this);
}
}
but it didn't work for when this method is called I only get the upper bar for copy/ paste/ search/ websearch... but no actual selection on the webview occur.
I have an Activity that populates two views on a ViewFlipper. I added an onTouch(View v, MotionEvent event) public boolean method to the Activity. The method is implemented so that when the person taps on the screen the ViewFlipper goes to the next view. It works great but some of the text is too long so I went into my XML file and surrounded the textfield in one of my ViewFlipper views with a linearlayout and then a ScrollView. But now when I'm viewing the fields that are too long and show a scroll bar, I can't display the previous view. The onTouch method in my main activity isn't being executed. I have not been able to figure this out. I've read some posts about implementing or overriding the methods in ScrollView but I don't know where to do this in my activity. Does anyone know how I can program ScrollView to not intercept but keep its ability to scroll the view?
ScrollView myScroll;
myScroll.setOnTouchListener(new OnTouchListener){
#Override
public boolean onTouch(View v, MotionEvent touchevent) {
switch (touchevent.getAction()) {
case MotionEvent.ACTION_DOWN: {
oldTouchValue = touchevent.getX();
break;
}
case MotionEvent.ACTION_UP: {
float currentX = touchevent.getX();
if (oldTouchValue < currentX) {
//left swipe
return true;
}
if (oldTouchValue > currentX) {
//right swipe
return true;
}
return false;
}
}
I'm using a UIScrollView for the first time, and I'm going crazy. I have several text boxes and labels on the scrollview. My text box event handled for TouchedDown, HandleTbLocationTouchDown (tb = Textbox), isn't firing half the time. My guess would be that the scrollview is swallowing the event because I have the exact same functionality on another View and it works perfectly fine.
Also, I set the size of the ScrollView in IB but that doesn't let it be scrollable. Setting it programmatically in my ViewDidLoad works though.
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
// Set the scrollableview
scrollView.Frame = new RectangleF(0,20, 320, 460);
// Set the initial scrollable view area size
scrollView.ContentSize = new SizeF(320, 550);
// For some reason this isn't always firing to do the offset,
// but the keyboard ALWAYS comes up.
tbLocation.TouchDown += HandleTbLocationTouchDown;
}
void HandleTbLocationTouchDown (object sender, EventArgs e)
{
scrollView.SetContentOffset(new PointF(0, 130), true);
}
Help?