0

I am making an application in which user has an option of searching patients. When the user searches for a patient, results come in the listview. But the problem is that the results are not bright enough for user to be able to be see properly, as you can see it in the below screenshot of the application (below Search patient button, the result is shown as 1234567890, abc, xyz. Please see thoroughly.)

Search patient screen

I don't know how to make it properly bright. The same problem appears on a real Android device also. Please could someone help me out.

Following is my code:-

SearchPatient.java

public class SearchPatient extends Activity implements PacketListener, OnItemClickListener, TextWatcher
{
private EditText mobileNumber;
private EditText firstName;
private EditText lastName;
private ListView patients;
private ArrayAdapter<String> adapter;

@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.search_patient);
    mobileNumber = (EditText) findViewById(R.id.mobile_number);
    mobileNumber.addTextChangedListener(this);
    firstName = (EditText) findViewById(R.id.first_name);
    firstName.addTextChangedListener(this);
    lastName = (EditText) findViewById(R.id.last_name);
    lastName.addTextChangedListener(this);
    patients = (ListView) findViewById(R.id.patients);
    patients.setOnItemClickListener(this);
    adapter = new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_list_item_1);
    patients.setAdapter(adapter);

    PacketFilter filter = new MessageTypeFilter(Message.Type.chat);
    Login.connection.addPacketListener(this, filter);
}

@Override
protected void onResume()
{
    super.onResume();
    PacketFilter filter = new MessageTypeFilter(Message.Type.chat);
    Login.connection.addPacketListener(this, filter);
}

@Override
protected void onStop()
{
    Login.connection.removePacketListener(this);
    super.onStop();
}

@Override
public void onTextChanged(CharSequence charSequence, int i1, int i2, int i3)
{
    return;
}

@Override
public void afterTextChanged(Editable editable)
{
    adapter.clear();

    String mobileNumber = this.mobileNumber.getText().toString();
    String firstName = this.firstName.getText().toString();
    String lastName = this.lastName.getText().toString();

    if(mobileNumber.equals(""))
        mobileNumber = null;
    if(firstName.equals(""))
        firstName = null;
    if(lastName.equals(""))
        lastName = null;

    searchPatient(mobileNumber, firstName, lastName);
}

@Override
public void beforeTextChanged(CharSequence charSequence, int i1, int i2, int i3)
{
    return;
}

public void searchPatient(View view)
{
    adapter.clear();

    String mobileNumber = this.mobileNumber.getText().toString();
    String firstName = this.firstName.getText().toString();
    String lastName = this.lastName.getText().toString();

    if(mobileNumber.equals(""))
        mobileNumber = null;
    if(firstName.equals(""))
        firstName = null;
    if(lastName.equals(""))
        lastName = null;

    searchPatient(mobileNumber, firstName, lastName);
}

private void searchPatient(String mobileNumber, String firstName, String lastName)
{
    Login.connection.sendPacket(getMessage(buildCommand(mobileNumber, firstName, lastName)));
}

private String buildCommand(String mobileNumber, String firstName, String lastName)
{
    StringBuilder commandBuilder = new StringBuilder();

    commandBuilder.append("##?##");
    commandBuilder.append("##app:patients##");
    commandBuilder.append("##" + mobileNumber + ", " + firstName + ", " + lastName + "##");

    return commandBuilder.toString();
}

private Message getMessage(String body)
{
    Message message = new Message("friend@domain", Message.Type.chat);
    message.setBody(body);

    return message;
}

@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l)
{
    String[] record = adapterView.getItemAtPosition(i).toString().split("\\,");
    if(record.length == 1)
        return;

    Intent patientDetails = new Intent(getApplicationContext(), PatientDetails.class);
    patientDetails.putExtra(PatientDetails.ACTION, PatientDetails.READ_PATIENT);
    patientDetails.putExtra(PatientDetails.RECORD, record);

    startActivity(patientDetails);
}

@SuppressLint("NewApi")
@Override
public void processPacket(Packet packet)
{
    Message message = (Message) packet;
    String reply = message.getBody().trim();

    if(reply.contains("."))
    {
        String[] records = reply.split("\\.");

        if(Build.VERSION.SDK_INT >= 11)
            adapter.addAll(records);
        else
            for(int i = 0; i < records.length; i++)
                adapter.add(records[i]);
    }
    else
        adapter.add(reply);

    adapter.notifyDataSetChanged();
}

@Override
public boolean onCreateOptionsMenu(Menu menu)
{
    getMenuInflater().inflate(R.menu.menu, menu);
    return true;
}

}

search_patient.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:orientation="vertical"
tools:context=".SearchPatient" >

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/mobile_number"/>
<EditText 
    android:id="@+id/mobile_number"
    android:layout_width="200dp"
    android:layout_height="wrap_content"
    android:inputType="number"/>
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/and_or"/>
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/first_name"/>
<EditText 
    android:id="@+id/first_name"
    android:layout_width="200dp"
    android:layout_height="wrap_content"
    android:inputType="text"/>
<TextView 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/last_name"/>
<EditText 
    android:id="@+id/last_name"
    android:layout_width="200dp"
    android:layout_height="wrap_content"
    android:inputType="text"/>
<Button 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/search_patient"
    android:onClick="searchPatient"/>
<ListView 
    android:id="@+id/patients"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:scrollbars="vertical"/>

</LinearLayout>
Osama Mohammed Shaikh
  • 1,219
  • 1
  • 16
  • 40

1 Answers1

2

Try to pass different Context to your adapter:

new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1);

More about this: Android Holo Light styling changes depending on chosen context

Community
  • 1
  • 1
Michał Z.
  • 4,119
  • 1
  • 22
  • 32