无法运行listview

时间:2015-06-28 15:08:55

标签: android listview

我是新来的。需要帮助我有运行我的应用程序的问题。这就是我的应用程序的运作方式:

1我在布局上编辑了文本,这样我就可以输入它并使用Button发送它 2编辑文本中的字符串将存储在数组中(String []) 3然后我把String放到我的ListView 4所以我可以在我输入的同一个屏幕上查看我的输入(就像做应用程序一样)

片段布局是否重要?

我无法运行它。需要帮助。谢谢

ListView listviewtest = (ListView) findViewById(R.id.listviewtest);
EditText edittexttest = (EditText) findViewById(R.id.edittexttest);
TextView textviewtest = (TextView) findViewById(R.id.textviewtest);
int x=0,y=0;
ArrayAdapter m_all_inputlist;
Button buttonenter = (Button) findViewById(R.id.buttontest);

String[] datatest = {""};

@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_tutor4);

    buttonenter.setOnClickListener(listener_buttonenter);
}

View.OnClickListener listener_buttonenter = new View.OnClickListener()
{
    @Override
    public void onClick(View v) {

        if(y<10)
        {
            y = insertdata(x);
        }
        else
        {
            exceeddatainsert();
        }

        storeinlistview(datatest);
    }
};

private void storeinlistview(String[] datatest)
{

    List<String> all_inputlist = new ArrayList<String>(Arrays.asList(datatest));

    m_all_inputlist = new ArrayAdapter<String>(null,R.layout.dataentered,R.id.textviewtest, all_inputlist);

    // Get a reference, which is listview, to the ListView, and attach this adapter to it.
    listviewtest.setAdapter(m_all_inputlist);
}

private void exceeddatainsert()
{
    AlertDialog.Builder warnexceed = new AlertDialog.Builder(tutor4.this);
    warnexceed.setTitle("Invalid");
    warnexceed.setPositiveButton("add button", insertnewtotal());
    warnexceed.setNegativeButton("OK", null);
    warnexceed.setMessage("You have inserted 10 things");
    warnexceed.create().show();
}

private DialogInterface.OnClickListener insertnewtotal() {
    return null;
}

private int insertdata(int x) {
    datatest[x] = edittexttest.getText().toString();
    x++;
    return x;
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_tutor4, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}

0 个答案:

没有答案