0

I filled a listview with items from the main activity and this is the MainActivity.class Data

public class MainActivity extends Activity {

// Declare Variables
ListView list;
ListViewAdapter adapter;
EditText editsearch;
String[] office_name;
String[] town_name;
String[] phone_number_01;
String[] phone_number_02;
String[] fax_number_01;
String[] fax_number_02;
ArrayList<ISF_LandLines> arraylist = new ArrayList<ISF_LandLines>();

@Override
public void onCreate(Bundle savedInstanceState) {
    // Remove title bar
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    // Remove notification bar
    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.listview_main);
    // Generate sample data
    office_name = new String[] { "فصيلة سن الفيل", "", "", "", "", "" };

    town_name = new String[] { "حرش تابت", "", "", "", "", "" };

    phone_number_01 = new String[] { "00961-1-511989", "------", "------",
            "------", "------", "------" };

    phone_number_02 = new String[] { "------", "------", "------",
            "------", "------", "------" };

    fax_number_01 = new String[] { "00961-1-480757", "------", "------",
            "------", "------", "------" };

    fax_number_02 = new String[] { "------", "------", "------", "------",
            "------", "------" };

    // Locate the ListView in listview_main.xml
    list = (ListView) findViewById(R.id.listview);

    for (int i = 0; i < office_name.length; i++) {
        ISF_LandLines wp = new ISF_LandLines(office_name[i], town_name[i],
                phone_number_01[i], phone_number_02[i], fax_number_01[i],
                fax_number_02[i]);
        // Binds all strings into an array
        arraylist.add(wp);
    }

    // Pass results to ListViewAdapter Class
    adapter = new ListViewAdapter(this, arraylist);

    // Binds the Adapter to the ListView
    list.setAdapter(adapter);

    // Locate the EditText in listview_main.xml
    editsearch = (EditText) findViewById(R.id.search);

    // Capture Text in EditText
    editsearch.addTextChangedListener(new TextWatcher() {

        @Override
        public void afterTextChanged(Editable arg0) {
            // TODO Auto-generated method stub
            String text = editsearch.getText().toString()
                    .toLowerCase(Locale.getDefault());
            adapter.filter(text);
        }

        @Override
        public void beforeTextChanged(CharSequence arg0, int arg1,
                int arg2, int arg3) {
            // TODO Auto-generated method stub
        }

        @Override
        public void onTextChanged(CharSequence arg0, int arg1, int arg2,
                int arg3) {
            // TODO Auto-generated method stub
        }
    });

}
}

but how can I fill my list view from string-array from strings.xml

because it's much easier to use string-array

1

1 Answer 1

0

Have an xml in your values folder

<?xml version="1.0" encoding="UTF-8"?>
<resources>
<array name="myresource">
        <item>Item 1</item>
        <item>Item 2</item>
        <item>Item 3</item>
</array>
</resources>

And in your code:

String[] mystringArray = getResources().getStringArray(R.array.myresource);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.