getting Random Numbers :
=======================
public ArrayList getRandomList() {
Random rand = new Random();
ArrayList alist = new ArrayList();
while (alist.size() < 5) {
int v = rand.nextInt(5);
if (!alist.contains(v)) {
alist.add(v);
}
}
return alist;
}
Getting Random Questions from ArrayList :
-----------------------------------
public ArrayList getQuestions(int level, ArrayList listObj){
ArrayList listObj2=new ArrayList();
Random r=new Random();
while(listObj2.size()<=20)
{
int r1=r.nextInt(listObj.size());
ModuleQuesBean mq=listObj.get(r1);
int lid=Integer.parseInt(mq.getLid());
if(lid==level)
{
if(!listObj2.contains(mq));
{
listObj2.add(mq);
}
}
}
for(int i=0;i<10;i++)
{
Log.w(" array list values ",listObj2.get(i).getQuestionid()+"");
}
return listObj2;
}
can u give clear explanation... i am getting confuse. please explain total code here
ReplyDeletegetting Random Numbers :
ReplyDelete=======================
public ArrayList getRandomList() {
// Random Class to provide random numbers
Random rand = new Random();
ArrayList alist = new ArrayList();
while (alist.size() < 5) {
int v = rand.nextInt(5);
// simply i am stroring random values in Array list , before storing checking whether value are existed or not , ifr value is does not exits storing that value in array list
if (!alist.contains(v)) {
alist.add(v);
}
}
// finally return array list which contains random values
return alist;
}
in android we use syntax like " ArrayList obj=new Arraylist "
ReplyDeletebut when i am using this code i getting errors.
and another doubt is ModuleQuestionBean is it a new class?
and where you define getquestionid();method
will u send me total code my mail id:shivakumar.martha@gmail.com
ModuleQuesBean is a new Class ( it's a bean )
Deletewhich is used to store data .
actaullay wat u want ?
what is ur requirement ?
i want to generate random questions and ansewers...
ReplyDeletetake one bean class store questions and answers and store that bean object in Arraylist , then try my logic
Deleteif u want to more come to skype : vsravan1
Are there in Skype now.. i sent request u.
Deletehi i am very new to android and java. i wanna generate non-repeated random numbers in android, which i wanna display as pyramid using number of TextViews. can anyone help me to find out the solution of it?
ReplyDeletefor that you have to take dynamic text views ,
Deletemay i know how many rows you wants to show in pyramid