btnGenerateNums.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
tvGeneratedNums.setText("");
tvResultInTextView.setVisibility(View.GONE);
tvResultInListView.setVisibility(View.GONE);
mList.clear();
if(isValid())
{
tvResultInTextView.setVisibility(View.VISIBLE);
tvResultInListView.setVisibility(View.VISIBLE);
RandomNumGenerator mRandomNumGen = new RandomNumGenerator(start,end);
for(int i=0;i<=end-start;i++)
{
int k = mRandomNumGen.generateNewRandom(i);
mList.add(k);
}
if(tvGeneratedNums.getText().toString().endsWith(","))
{
tvGeneratedNums.setText(tvGeneratedNums.getText().toString().substring(0, tvGeneratedNums.getText().toString().length()-1));
}
}
mAdapter = new ArrayAdapter<Integer>(mContext, android.R.layout.simple_list_item_1, mList);
lvGeneratedNums.setAdapter(mAdapter);
}
});
我想将我生成的密码显示在列表视图中,所以我写了这个,但这只给我一个这样的数字
3
5
10
6
9
8
但我想要的是
3 5 10 6 9 8
8 10 6 9 3 5
5 10 9 8 3 6
9 5 6 10 3 8
等等......
答案 0 :(得分:0)
你需要循环生成更多数字,就像你想要的那样,这里有一些代码:
btnGenerateNums.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
tvGeneratedNums.setText("");
tvResultInTextView.setVisibility(View.GONE);
tvResultInListView.setVisibility(View.GONE);
mList.clear();
if(isValid())
{
tvResultInTextView.setVisibility(View.VISIBLE);
tvResultInListView.setVisibility(View.VISIBLE);
RandomNumGenerator mRandomNumGen = new RandomNumGenerator(start,end);
for(int i=0;i<=end-start;i++) {
String randPass = "";
for(int j=0;j<=5;j++) {
int ch = mRandomNumGen.generateNewRandom(i);
randPass += " " +String.valueOf(ch);
}
mList.add(randPass);
}
if(tvGeneratedNums.getText().toString().endsWith(","))
{
tvGeneratedNums.setText(tvGeneratedNums.getText().toString().substring(0, tvGeneratedNums.getText().toString().length()-1));
}
}
mAdapter = new ArrayAdapter<Integer>(mContext, android.R.layout.simple_list_item_1, mList);
lvGeneratedNums.setAdapter(mAdapter);
}
});
with mList是List&lt; String&gt;;,我不测试这段代码,只是给你一个选项。