>
> A ListView is usually not edited in place and actually are very friendly 
>> when you try to.
>>
>
> Your statements seem contradictory. You say a list view is not edited in 
> place.
> Then you say a list view is very friendly when you try to edit it in place?
>

Whoops, sorry about that, it should say "actually are not very friendly".
 

> It might be better just to use a LinearLayout wrapped in a ScrollView and 
>> dynamically add EditText to the LinearLayout assigning different IDs as you 
>> go.  That way you can access those at any time and you won't have to fight 
>> with the ListView.
>>
>
> Yes, in the end overriding getView was giving me lots of problems so I 
> dumped the listview altogether
> and used inflation of XML rows in a linearlayout in a scrollview in a 
> linearlayout. This may be inefficient
> but I would have had to keep an array of rows around anyways even if I 
> implemented a listview with an
> adapter...
>
> what is not clear right now is what advantages/disadvantages a listview 
> with adapter may have had
> compared to views added to a plain linearlayout.
>

Not really sure there. So many way to get the same thing done, unless a 
Android developer actually posts, we are all just trying things that work.
 

> I know people don't like to share ideas for programs, but can you explain a 
>> little more why you would have so many edit in place boxes that you need a 
>> ListView?
>>
>
> Since I don't want my users to have to go through a separate screen to 
> input information which
> could be edited in place, I do it right there. Just like with SQL queries, 
> some returned rows have
> unique fields, and some do not, hence the need to update textedits 
> concurrently.
>

 Gotcha, seems straight forward enough

Try this, this should be full working code:

--- XML file for Activity ---

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"; 
android:layout_width="fill_parent" android:layout_height="fill_parent">
    <LinearLayout android:id="@+id/llHolder" 
android:layout_width="fill_parent" android:layout_height="fill_parent" 
android:orientation="vertical">
    </LinearLayout>
</ScrollView>

--- Activity ---

public class TestProjectActivity extends Activity
{
    private static final int EDIT_COUNT = 7;
    private LinearLayout llHolder;
    private LinearLayout.LayoutParams llParams = new 
LinearLayout.LayoutParams( LinearLayout.LayoutParams.FILL_PARENT, 
LinearLayout.LayoutParams.WRAP_CONTENT );
    private HasFocus hfFocus = new HasFocus();
    private Watcher wWatcher = new Watcher();

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView( R.layout.main );

        llHolder = (LinearLayout)findViewById( R.id.llHolder );

        createEdits( EDIT_COUNT );
    }

    private void createEdits( int iNumber )
    {
        llHolder.removeAllViews(); // Just in case we reuse the holder

        for( int iX = 1; iX <= iNumber; iX++ )
        {
            EditText etNew = new EditText( this );
            etNew.setId( iX );
            etNew.setOnFocusChangeListener( hfFocus );

            llHolder.addView( etNew, llParams );
        }
    }

    private void updateEdits( String sNew, int iCount, int iSkip )
    {
        Log.i( "Stuff", "String: " + sNew + " - iCount: " + iCount + " - 
iSkip: " + iSkip );
        for( int iX = 1; iX <= iCount; iX++ )
        {
            if( iX == iSkip ) continue;

            EditText etEdit = (EditText)findViewById( iX );
            etEdit.setText( sNew + ": " + iX );
        }
    }

    private class HasFocus implements OnFocusChangeListener
    {
        @Override
        public void onFocusChange( View v, boolean hasFocus )
        {
            if( hasFocus )
            {
                wWatcher.iID = v.getId();
                ((EditText)v).addTextChangedListener( wWatcher );
            }
            else
            {
                ((EditText)v).removeTextChangedListener( wWatcher );
            }
        }
    }

    private class Watcher implements TextWatcher
    {
        public int iID;

        @Override
        public void afterTextChanged( Editable s )
        {
            updateEdits( s.toString(), EDIT_COUNT, iID );
        }

        @Override
        public void beforeTextChanged( CharSequence s, int start, int count, 
int after ) { }

        @Override
        public void onTextChanged( CharSequence s, int start, int before, 
int count ) { }
    }
}

One thing I did add to the code was a focus watcher. I did this because if 
you put a text watcher on all of them, once you edit one you will start an 
endless loops as it will fire the text watchers on others if you update 
them.

I didn't do an array backing, but you could use that. I was just trying to 
get something as simple as possible for you to work with as a base.

See if that helps at all.

Steven
Studio LFP
http://www.studio-lfp.com

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to