努力将rss文件中的数据导入android中的数组列表

时间:2015-04-19 15:01:35

标签: android rss

我正在创建一个应用程序,该应用程序需要将rss文件中的信息(最终将是一个实际的提要但尚不存在)放入回收站视图中,每个单独的卡片只显示一小段信息当用户点击卡片时,它会打开另一个活动以显示所有信息。但是,我不确定如何访问本地文件,因为我将实际的实时源。任何帮助将不胜感激。

我的rss文件采用xml格式,名为dummy_RSS.rss。

我有一个类来指定所需的字符串

public class EventViewDetails {

private String title;
private String location;
private String locLat;
private String locLong;
private String date;
private String timeStart;
private String timeFinish;
private String desc;

public String getTitle() {
    return title;
}

public void setTitle(String title) {
    this.title = title;
}

public String getLocation() {
    return location;
}

public void setLocation(String location) {
    this.location = location;
}

public String getLocLat() {
    return locLat;
}

public void setLocLat(String locLat) {
    this.locLat = locLat;
}

public String getLocLong() {
    return locLong;
}

public void setLocLong(String locLong) {
    this.locLong = locLong;
}

public String getDate() {
    return date;
}

public void setDate(String date) {
    this.date = date;
}

public String getTimeStart() {
    return timeStart;
}

public void setTimeStart(String timeStart) {
    this.timeStart = timeStart;
}

public String getTimeFinish() {
    return timeFinish;
}

public void setTimeFinish(String timeFinish) {
    this.timeFinish = timeFinish;
}

public String getDesc() {
    return desc;
}

public void setDesc(String desc) {
    this.desc = desc;
}
}

我有一个类将来自feed的数据解析为上面的字符串

public class ParseEventDetails {

private String data;
private ArrayList<EventViewDetails> events;

public ParseEventDetails(String xmlData) {
    data = xmlData;
    events = new ArrayList<EventViewDetails>();
}

public ArrayList<EventViewDetails> getEvents() {
    return events;
}

public boolean process() {
    boolean operationStatus = true;
    EventViewDetails currentEvent = null;
    boolean inEntry = false;
    String textValue = "";
    XmlPullParserFactory factory = null;
    try {
        factory = XmlPullParserFactory.newInstance();
        factory.setNamespaceAware(true);
        XmlPullParser xpp = factory.newPullParser();
        xpp.setInput(new StringReader(this.data));
        int type = xpp.getEventType();
        while (type != XmlPullParser.END_DOCUMENT) {
            String tagName = xpp.getName();
            if (type == XmlPullParser.START_TAG) {
                if (tagName.equalsIgnoreCase("event")) {
                    inEntry = true;
                    currentEvent = new EventViewDetails();
                }
            } else if (type == XmlPullParser.TEXT) {
                textValue = xpp.getText();
            } else if (type == XmlPullParser.END_TAG) {
                if (inEntry) {
                    if (tagName.equalsIgnoreCase("event")) {
                        events.add(currentEvent);
                        inEntry = false;
                    }
                    if (tagName.equalsIgnoreCase("title")) {
                        currentEvent.setTitle(textValue);
                    } else if (tagName.equalsIgnoreCase("location")) {
                        currentEvent.setLocation(textValue);
                    } else if (tagName.equalsIgnoreCase("date")) {
                        currentEvent.setDate(textValue);
                    } else if (tagName.equalsIgnoreCase("timestart")) {
                        currentEvent.setTimeStart(textValue);
                    } else if (tagName.equalsIgnoreCase("timefinish")) {
                        currentEvent.setTimeFinish(textValue);
                    } else if (tagName.equalsIgnoreCase("loclat")) {
                        currentEvent.setLocLat(textValue);
                    } else if (tagName.equalsIgnoreCase("loclong")) {
                        currentEvent.setLocLong(textValue);
                    } else if (tagName.equalsIgnoreCase("description")) {
                        currentEvent.setDesc(textValue);
                    }
                }
            }
        }
        type = xpp.next();
    } catch (Exception e) {
        e.printStackTrace();
        operationStatus = false;
    }
    return operationStatus;
}
}

我有适用于回收站视图的适配器

public class EventCalenderAdapter extends RecyclerView.Adapter<EventCalenderAdapter.ViewHolder> {

String xmlData;

static class ViewHolder extends RecyclerView.ViewHolder {
    CardView cardView;
    TextView titleView;

    public ViewHolder(CardView card) {
        super(card);
        cardView = card;
        titleView = (TextView) card.findViewById(R.id.text1);
    }
}

@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int i) {
    CardView v = (CardView) LayoutInflater.from(parent.getContext()).inflate(R.layout.event_task, parent, false);
    return new ViewHolder(v);
}

@Override
public void onBindViewHolder(ViewHolder viewHolder, final int i) {
    final Context context = viewHolder.titleView.getContext();
    viewHolder.titleView.setText(xmlData[i]);

    viewHolder.cardView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            ((OnEventView) context).eventView(i);
        }
    });
}

@Override
public int getItemCount() {
    return xmlData.length;
}
}

我有我的片段

public class EventCalenderFragment extends Fragment {

RecyclerView recyclerView;
EventCalenderAdapter adapter;


public EventCalenderFragment() {
    // Required empty public constructor
}

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    adapter = new EventCalenderAdapter();
}


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    final View v = inflater.inflate(R.layout.fragment_event_calender, container, false);
    recyclerView = (RecyclerView) v.findViewById(R.id.recycler);
    recyclerView.setAdapter(adapter);
    recyclerView.setHasFixedSize(true);
    recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
    return v;
}


}

正如我所说,我不知道如何访问本地文件或在何处进行初始访问。

1 个答案:

答案 0 :(得分:0)

你必须将phpmyadmin配置中的访问配置更改为“允许任何”,然后url将是这样的:localhost / your_php_project_name / your_php_file 请注意,文件your_php_file必须返回xml数据或文件