Strict Standards: Non-static method utf_normalizer::nfc() should not be called statically in /www/htdocs/w006661d/anddev/includes/utf/utf_tools.php on line 1781
[phpBB Debug] PHP Notice: in file /includes/session.php on line 1007: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /includes/session.php on line 1007: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /includes/session.php on line 1007: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)

Strict Standards: Non-static method utf_normalizer::nfc() should not be called statically in /www/htdocs/w006661d/anddev/includes/utf/utf_tools.php on line 1781

Strict Standards: Non-static method utf_normalizer::nfc() should not be called statically in /www/htdocs/w006661d/anddev/includes/utf/utf_tools.php on line 1781
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4362: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4364: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4365: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4366: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
anddev.org • View topic - How to compare tags of buttons?

How to compare tags of buttons?

Put your problem here if it does not fit any of the other categories.

How to compare tags of buttons?

Postby Nabukodonosor » Sat Mar 23, 2013 9:48 pm

I have bunch of buttons to which I have tags set. I then shuffle them and a user needs to connect correct terms within the button's text. How to compare if the tags are same? Here's my code so far:

Code: Select all
public class Spojnice extends Activity implements View.OnClickListener{
       
        private boolean mShouldTakeAction;
       
           
    // labelForButton and tagForButton
       class MyStruct {
       public MyStruct (String lab, String t){
            label = lab;
            tag = t;
        }
       private String label;
       private String tag;
       }
       
       final OnClickListener clickListener = new OnClickListener() {
            public void onClick(View v) {
               
             Button button = (Button)v;
             button.setBackgroundColor(Color.YELLOW);
             
          if (mShouldTakeAction)
      {

      }
      mShouldTakeAction = !mShouldTakeAction;
                }
         };
       
       
        LinkedList<Long> mAnsweredQuestions = new LinkedList<Long>();
       
        private String generateWhereClause(){
            StringBuilder result = new StringBuilder();
            for (Long l : mAnsweredQuestions){
                result.append(" AND _ID <> " + l);
            }
            return result.toString();
        }
        private TextView pitanje;
       
        Button a1,a2,a3,a4,a5,a6,a7,a8,b1,b2,b3,b4,b5,b6,b7,b8;

       
        protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
               
                setContentView(R.layout.spojnice);
               
                a1 = (Button) findViewById(R.id.bA1);
                a2 = (Button) findViewById(R.id.bA2);
                a3 = (Button) findViewById(R.id.bA3);
                a4 = (Button) findViewById(R.id.bA4);
                a5 = (Button) findViewById(R.id.bA5);
                a6 = (Button) findViewById(R.id.bA6);
                a7 = (Button) findViewById(R.id.bA7);
                a8 = (Button) findViewById(R.id.bA8);
                b1 = (Button) findViewById(R.id.bB1);
                b2 = (Button) findViewById(R.id.bB2);
                b3 = (Button) findViewById(R.id.bB3);
                b4 = (Button) findViewById(R.id.bB4);
                b5 = (Button) findViewById(R.id.bB5);
                b6 = (Button) findViewById(R.id.bB6);
                b7 = (Button) findViewById(R.id.bB7);
                b8 = (Button) findViewById(R.id.bB8);
                pitanje = (TextView) findViewById(R.id.tvPitanje);
               
                nextQuestion();

            }

        public void nextQuestion() {
               
                TestAdapter mDbHelper = new TestAdapter(this);
                mDbHelper.createDatabase();
               
                try{
               
                mDbHelper.open();
               
                Cursor c = mDbHelper.getTestData(generateWhereClause());
               
                mAnsweredQuestions.add(c.getLong(0));
             
                ArrayList<MyStruct> labelsA = new ArrayList<MyStruct>();
                ArrayList<MyStruct> labelsB = new ArrayList<MyStruct>();
               
                labelsA.add(new MyStruct(c.getString(2), "1")); // this tag should be the same to button that matches
                labelsB.add(new MyStruct(c.getString(3), "1"));
                labelsA.add(new MyStruct(c.getString(4), "2"));
                labelsB.add(new MyStruct(c.getString(5), "2"));
                labelsA.add(new MyStruct(c.getString(6), "3"));
                labelsB.add(new MyStruct(c.getString(7), "3"));
                labelsA.add(new MyStruct(c.getString(8), "4"));
                labelsB.add(new MyStruct(c.getString(9), "4"));
                labelsA.add(new MyStruct(c.getString(10), "5"));
                labelsB.add(new MyStruct(c.getString(11), "5"));
                labelsA.add(new MyStruct(c.getString(12), "6"));
                labelsB.add(new MyStruct(c.getString(13), "6"));
                labelsA.add(new MyStruct(c.getString(14), "7"));
                labelsB.add(new MyStruct(c.getString(15), "7"));
                labelsA.add(new MyStruct(c.getString(16), "8"));
                labelsB.add(new MyStruct(c.getString(17), "8"));

                Collections.shuffle(labelsA);
                Collections.shuffle(labelsB);
               
                pitanje.setText(c.getString(1));

                a1.setText(labelsA.get(0).label);
                a1.setTag(labelsA.get(0).tag);
                a1.setOnClickListener(clickListener);
                b1.setText(labelsB.get(0).label);
                b1.setTag(labelsB.get(0).tag);
                b1.setOnClickListener(clickListener);
                a2.setText(labelsA.get(1).label);
                a2.setTag(labelsA.get(1).tag);
                a2.setOnClickListener(clickListener);
                b2.setText(labelsB.get(1).label);
                b2.setTag(labelsB.get(1).tag);
                b2.setOnClickListener(clickListener);
                a3.setText(labelsA.get(2).label);
                a3.setTag(labelsA.get(2).tag);
                a3.setOnClickListener(clickListener);
                b3.setText(labelsB.get(2).label);
                b3.setTag(labelsB.get(2).tag);
                b3.setOnClickListener(clickListener);
                a4.setText(labelsA.get(3).label);
                a4.setTag(labelsA.get(3).tag);
                a4.setOnClickListener(clickListener);
                b4.setText(labelsB.get(3).label);
                b4.setTag(labelsB.get(3).tag);
                b4.setOnClickListener(clickListener);
                a5.setText(labelsA.get(4).label);
                a5.setTag(labelsA.get(4).tag);
                a5.setOnClickListener(clickListener);
                b5.setText(labelsB.get(4).label);
                b5.setTag(labelsB.get(4).tag);
                b5.setOnClickListener(clickListener);
                a6.setText(labelsA.get(5).label);
                a6.setTag(labelsA.get(5).tag);
                a6.setOnClickListener(clickListener);
                b6.setText(labelsB.get(5).label);
                b6.setTag(labelsB.get(5).tag);
                b6.setOnClickListener(clickListener);
                a7.setText(labelsA.get(6).label);
                a7.setTag(labelsA.get(6).tag);
                a7.setOnClickListener(clickListener);
                b7.setText(labelsB.get(6).label);
                b7.setTag(labelsB.get(6).tag);
                b7.setOnClickListener(clickListener);
                a8.setText(labelsA.get(7).label);
                a8.setTag(labelsA.get(7).tag);
                a8.setOnClickListener(clickListener);
                b8.setText(labelsB.get(7).label);
                b8.setTag(labelsB.get(7).tag);
                b8.setOnClickListener(clickListener);

                }
               
               
                finally{
                mDbHelper.close();
        }
        }
        public void onClick(View arg0) {
                // TODO Auto-generated method stub
               
        }
}
Nabukodonosor
Freshman
Freshman
 
Posts: 5
Joined: Fri Feb 22, 2013 1:56 pm

Top

Re: How to compare tags of buttons?

Postby fChopin » Sat May 04, 2013 1:33 pm

you should setTag() with Object ex.
String, Boolean, Integer

ex.
Code: Select all
      Button button = (Button)findViewById(R.id.button1);
      button.setTag(new String("button1"));
      button.setOnClickListener(new OnClickListener() {
         @Override
         public void onClick(View v) {
            Button b = (Button)v;
            Toast.makeText(getApplicationContext(), b.getTag().toString(), Toast.LENGTH_SHORT).show();
         }
      });
fChopin
Freshman
Freshman
 
Posts: 3
Joined: Sat May 04, 2013 10:53 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 9 guests