• 14
name

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191

Backtrace:

File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

I have the next XML file:

<?xml version="1.0" encoding="utf-8"?>
<myxml source-info-url="http://url.com/" source-info-name="URLName" generator-info-url="http://url.org/">
    <tag1 id="92">
        <display-name>1</display-name>
        <icon src="http://some_valid_url.gif" />
    </tag1>
    <tag1 id="107">
        <display-name>2</display-name>
        <icon src="http://some_valid_url.gif" />
    </tag1>
    <tag1 id="175">
        <display-name>3</display-name>
        <icon src="http://some_valid_url.gif" />
    </tag1>
    <tag1 id="346">
        <display-name>4</display-name>
        <icon src="http://some_valid_url.gif" />
    </tag1>
    <tag1 id="357">
        <display-name>5</display-name>
        <icon src="http://some_valid_url.gif" />
    </tag1>


    <tag2 attr1="" attr2="" tag1="92">
        <exampletag1>Text</exampletag1>
        <exampletag2 lang="en">Text</exampletag2>
        <exampletag3 id="21">Text</exampletag3>
        <desc lang="en">Text.</desc>
        <exampletag4>6</exampletag4>
    </tag2>
    <tag2 attr1="" attr2="" tag1="92">
        <exampletag1>&quot;Text&quot;.</exampletag1>
        <exampletag2 lang="en">Text</exampletag2>
    </tag2>
    <tag2 attr1="" attr2="" tag1="92">
        <exampletag1>Text.</exampletag1>
        <exampletag2 lang="en">Text</exampletag2>
    </tag2>

    <tag2 attr1="" attr2="" tag1="107">
        <exampletag1>&quot;Text&quot;.</exampletag1>
        <exampletag2 lang="en">Text</exampletag2>
        <exampletag3 id="22">Text</exampletag3>
        <exampletag3 id="32">Text</exampletag3>
        <exampletag3 id="21">Text</exampletag3>
        <desc lang="en">Text.</desc>
        <exampletag4>6</exampletag4>
    </tag2>
</myxml>

<tag2> will repeat several thousand times. <tag1> will repeat several hundred times.

I have parsed XML with XMLPullParser, created 2 custom adapters and created 2 ListViews:

listView.setAdapter(adapter);//include all of <tag1>
listView2.setAdapter(adapterPr);//include all of <tag2>

In activity by default I am showing listView, and the listView2 is GONE.

So now I have two ListViews filled with information. Many information.

By clicking on items in listView I want to read attribute <tag1 id=""> and compare it with attribute <tag2 tag1="107">.

If comparing succesful - show in listview2 only items with this ID.

By clicking back button I am returning to listView and want to repeat this actions again and again.

For this I have tried to write the next OnItemClickListener(including commented, also tried without for):

    private List<ItemTAG1> items = new ArrayList();
    private List<ItemTAG2> items2 = new ArrayList();
...
    listView.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                    for(int i=0; i<=items.size(); i++) {
    //                    ItemTAG1 itemTAG1 = adapter.getItem(position);
    //                    ItemTAG2 itemTAG2 = adapter2.getItem(position);
                        ItemTAG1 itemTAG1 = items.get(i);
                        ItemTAG2 itemTAG2 = items2.get(i);

                        String tmpCI = itemTAG1.getTAGId();
                        String tmpPCI = itemTAG2.getTAG2id();

                        if (!tmpCI.equals(tmpPCI)) {
                            listView.setVisibility(View.GONE);
                            listViewProgrammes.setVisibility(View.VISIBLE);
                        } else {
    //                        adapterPr.remove(item2);
                            Toast.makeText(MyaActivity.this, "No data for this item!", Toast.LENGTH_SHORT).show();
                        }

                   }

But everything what I have tried is wrong and I still can not achieve what I need.

I want to wrote what is happening when I am executing this code, but I understood that I have not done anything for filtering listView2 from useless items for certain item listView and I have no idea what I should do for this.

How I can compare values and show in listView2 what I need?

Try this:

  1. Inside ItemTag2 class, add:

    @Override
    public String toString() {
        return getTAG2id();
    }
    
  2. Change OnItemClickListener to this:

        listView.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            ItemTAG1 itemTAG1 = items.get(position);
            String tmpCI = itemTAG1.getTAGId();
            adapter2.getFilter().filter(tmpCI, new Filter.FilterListener() {
                @Override
                public void onFilterComplete(int count) {
                    if(count > 0) {
                        listView2.setVisibility(View.VISIBLE);
                    }else{
                        listView2.setVisibility(View.GONE);
                        Toast.makeText(MyaActivity.this, "No data for this item!", Toast.LENGTH_SHORT).show();
                    }
    
                }
            });
        }
    

Hope that helps!

  • 1
Reply Report
      • 2
    • I have wrote wrong information. Issue is the next: in the second item of listView2 I have elements from the first item of listView2. Count of this elements is right, but text is wrong. How I can fix this?
      • 1
    • My wild guess is in getView(), you get data item directly from data list [e.g. ItemTAG2 itemTAG2 = items.get(position);], change it to use getItem() [e.g. ItemTAG2 itemTAG2 = getItem();]. Otherwise, post the adapter code of listView2.
      • 1
    • Yes, you are right, about getting data item directly from data list .getItem() needs parameter int - this should be position?