0

我正在制作一个用户可以选择搜索患者的应用程序。当用户搜索患者时,结果会出现在列表视图中。但问题是结果不够亮,用户无法正常看到,正如您在下面的应用程序屏幕截图中看到的那样(在搜索患者按钮下方,结果显示为 1234567890,abc,xyz。请仔细看。)

搜索患者屏幕

我不知道如何使它正确明亮。同样的问题也出现在真正的 Android 设备上。请有人能帮帮我。

以下是我的代码:-

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

1 回答 1

2

尝试将不同的内容传递Context给您的适配器:

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

有关此的更多信息:Android Holo Light 样式会根据所选上下文进行更改

于 2013-06-03T10:44:34.570 回答