如何在列表中显示生成的密码
How to show generated password in list
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
等等...
你只需要循环生成更多你想要的数字,这里有一些代码:
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 is List;,我不测试这段代码,只是给你一个选项。
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
等等...
你只需要循环生成更多你想要的数字,这里有一些代码:
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 is List