Hi all!

Im trying to fill an autocompletetextview with data that i retrieve
from a database, so the next time we do a search that data will be in
the autocompletetextview suggestions.

The problem is that, I can view the listView associated with the
autocompletetextview (and it retrieves the data from the database
without any problem), but if i click on a single element of the
textview instead of having the string I picked on the autocomplete
textview I have an string like "sql.cur...@...".

I dont have any problems with the database as I followed the notepad
tutorial and it works well.

Thank you all and here is the code:


Java class:

import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

import android.app.Activity;
import android.app.ListActivity;
import android.content.ContentResolver;
import android.content.Intent;
import android.os.Bundle;
import android.provider.Contacts;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.CursorAdapter;
import android.widget.ListView;
import android.widget.TextView;

import android.widget.SimpleCursorAdapter;
import android.database.Cursor;

//antes extends activity
public class RemoteIR extends ListActivity implements OnClickListener{

    static String ipquery;
    static String ipadress;
    static int ipport;

    protected static final String RESULTS="results";

    @SuppressWarnings("unchecked")
    ArrayList dataSend;
    int noSend;
    int startIndex =0;
    int count = 100;

    //antes textview
    AutoCompleteTextView adress;
    TextView port;
    TextView query;
    Button search, exit;

    private int mDataNumber = 1;
    private RemoteIrDbAdapter mDbHelper; //= null;


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

        mDbHelper = new RemoteIrDbAdapter(this);
        mDbHelper.open();

        //antes TextView
        adress = (AutoCompleteTextView)this.findViewById(R.id.adress);


        SimpleCursorAdapter notes = fillData();
        adress.setAdapter(notes);



        port = (TextView)this.findViewById(R.id.port);
        query = (TextView)this.findViewById(R.id.query);

        search = (Button)this.findViewById(R.id.search);
        search.setOnClickListener(this);

        exit = (Button)this.findViewById(R.id.exit);
        exit.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {

                finish();
            }
        });

    }

    @SuppressWarnings({ "unchecked" })
    public void onClick(View v) {

        ipquery = query.getText().toString();
        ipadress = adress.getText().toString();

        ipport = Integer.parseInt(port.getText().toString());

        java.util.Date tempDate = new Date();
        String date = tempDate.toString();

        mDbHelper.createQueryData(ipadress, date);
        fillData();
        mDbHelper.close();

        Log.d("RemoteIR", "creamos cliente");

        Client results;
        Thread cThread = new Thread(results = new Client(startIndex,
count));

        Log.d("RemoteIR", "arrancamos cliente");

        cThread.start();

        try {
            cThread.join();

            ArrayList finalResults = results.getResults();

            int finalNo = finalResults.size();

            Intent intent = new Intent();

            intent.setClass(RemoteIR.this, DisplayResult.class);

            dataSend = finalResults;
            noSend = finalNo;

            int startIndex = 0;
            int endIndex = 10; //ANTES 9

            ActivitySwitchInfo asi = new ActivitySwitchInfo(dataSend,
noSend, startIndex, endIndex);

            intent.putExtra(RESULTS, asi);

            startActivity(intent);

            finish();

         }
         catch (InterruptedException e) {
            Log.e("RemoteIR", "Join interrupted", e);
         }

    }


     private void createData() {
            String queryDataName = "QueryData " + mDataNumber++;

            mDbHelper.createQueryData(queryDataName,"");
            fillData();
        }


    private SimpleCursorAdapter fillData() {
        Cursor c = mDbHelper.fetchAllQueryData();
        startManagingCursor(c);
        String[] from = new String[] { RemoteIrDbAdapter.KEY_QUERY};
        int[] to = new int[] { R.id.row1 };

        SimpleCursorAdapter notes =
            new SimpleCursorAdapter(this, R.layout.query_row, c, from,
to);


        return notes;
        //setListAdapter(notes);
    }


}


XML files:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="@+id/widget28"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android";
>
<LinearLayout
android:id="@+id/widget29"
android:layout_width="250px"
android:layout_height="180px"
android:orientation="vertical"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
>

<ListView android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:id="@android:id/list"></ListView>

<AutoCompleteTextView
android:id="@+id/adress"
android:layout_width="fill_parent"
android:layout_height="50px"
android:text="IP"
android:textSize="18sp"

>
</AutoCompleteTextView>
<EditText
android:id="@+id/port"
android:layout_width="fill_parent"
android:layout_height="50px"
android:text="Port"
android:textSize="18sp"
>
</EditText>
<EditText
android:id="@+id/query"
android:layout_width="fill_parent"
android:layout_height="50px"
android:text="Query"
android:textSize="18sp"
>
</EditText>
</LinearLayout>
<Button
android:id="@+id/search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Search"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
>
</Button>
<Button
android:id="@+id/exit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Exit"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
>
</Button>
</RelativeLayout>


And:

<?xml version="1.0" encoding="utf-8"?>
<TextView android:id="@+id/row1"
    xmlns:android="http://schemas.android.com/apk/res/android";
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>

Ty!

-- 
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